Gemini ocr url (#917)

* add url setting

* add url setting

* add model

* add model
This commit is contained in:
Asuka Minato 2024-07-22 16:08:19 +09:00 committed by GitHub
parent ae7f825b66
commit 674b4c232c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -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)

View File

@ -270,7 +270,9 @@
},
"geminiocr": {
"args": {
"key": ""
"key": "",
"url": "https://generativelanguage.googleapis.com/v1",
"model": "gemini-1.5-flash"
}
},
"xunfei": {
@ -317,4 +319,4 @@
}
}
}
}
}