From 674b4c232c1951daaae3dbaa6287b2a1c6faed78 Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Mon, 22 Jul 2024 16:08:19 +0900 Subject: [PATCH] Gemini ocr url (#917) * add url setting * add url setting * add model * add model --- LunaTranslator/LunaTranslator/ocrengines/geminiocr.py | 7 ++++++- LunaTranslator/files/defaultconfig/ocrsetting.json | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/LunaTranslator/LunaTranslator/ocrengines/geminiocr.py b/LunaTranslator/LunaTranslator/ocrengines/geminiocr.py index 43209655..6ef74b65 100644 --- a/LunaTranslator/LunaTranslator/ocrengines/geminiocr.py +++ b/LunaTranslator/LunaTranslator/ocrengines/geminiocr.py @@ -6,7 +6,11 @@ from ocrengines.baseocrclass import baseocr class OCR(baseocr): def ocr(self, imagebinary): self.checkempty(["key"]) + self.checkempty(["url"]) + self.checkempty(["model"]) api_key = self.config["key"] + url = self.config["url"] + model = self.config["model"] image_data = base64.b64encode(imagebinary).decode("utf-8") # Prepare the request payload @@ -23,7 +27,8 @@ class OCR(baseocr): # Set up the request headers and URL headers = {"Content-Type": "application/json"} - url = f"https://generativelanguage.googleapis.com/v1/models/gemini-1.5-flash:generateContent?key={api_key}" + # by default https://generativelanguage.googleapis.com/v1 + url = f"{url}/models/{model}:generateContent?key={api_key}" # Send the request response = requests.post(url, headers=headers, json=payload, proxies=self.proxy) diff --git a/LunaTranslator/files/defaultconfig/ocrsetting.json b/LunaTranslator/files/defaultconfig/ocrsetting.json index 14fc7a61..2396c16d 100644 --- a/LunaTranslator/files/defaultconfig/ocrsetting.json +++ b/LunaTranslator/files/defaultconfig/ocrsetting.json @@ -270,7 +270,9 @@ }, "geminiocr": { "args": { - "key": "" + "key": "", + "url": "https://generativelanguage.googleapis.com/v1", + "model": "gemini-1.5-flash" } }, "xunfei": { @@ -317,4 +319,4 @@ } } } -} \ No newline at end of file +}