mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
Gemini ocr url (#917)
* add url setting * add url setting * add model * add model
This commit is contained in:
parent
ae7f825b66
commit
674b4c232c
@ -6,7 +6,11 @@ from ocrengines.baseocrclass import baseocr
|
|||||||
class OCR(baseocr):
|
class OCR(baseocr):
|
||||||
def ocr(self, imagebinary):
|
def ocr(self, imagebinary):
|
||||||
self.checkempty(["key"])
|
self.checkempty(["key"])
|
||||||
|
self.checkempty(["url"])
|
||||||
|
self.checkempty(["model"])
|
||||||
api_key = self.config["key"]
|
api_key = self.config["key"]
|
||||||
|
url = self.config["url"]
|
||||||
|
model = self.config["model"]
|
||||||
image_data = base64.b64encode(imagebinary).decode("utf-8")
|
image_data = base64.b64encode(imagebinary).decode("utf-8")
|
||||||
|
|
||||||
# Prepare the request payload
|
# Prepare the request payload
|
||||||
@ -23,7 +27,8 @@ class OCR(baseocr):
|
|||||||
|
|
||||||
# Set up the request headers and URL
|
# Set up the request headers and URL
|
||||||
headers = {"Content-Type": "application/json"}
|
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
|
# Send the request
|
||||||
response = requests.post(url, headers=headers, json=payload, proxies=self.proxy)
|
response = requests.post(url, headers=headers, json=payload, proxies=self.proxy)
|
||||||
|
@ -270,7 +270,9 @@
|
|||||||
},
|
},
|
||||||
"geminiocr": {
|
"geminiocr": {
|
||||||
"args": {
|
"args": {
|
||||||
"key": ""
|
"key": "",
|
||||||
|
"url": "https://generativelanguage.googleapis.com/v1",
|
||||||
|
"model": "gemini-1.5-flash"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"xunfei": {
|
"xunfei": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user