Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ckundo authored Jan 3, 2024
1 parent d6de179 commit e227964
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions addon/globalPlugins/image-describer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@
module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "vendor"))
sys.path.append(module_path)

import json
import pyscreeze
import api
import base64
import globalPluginHandler
import os
import requests
import urllib.request
import tempfile
import threading
import tones
import ui


class GlobalPlugin(globalPluginHandler.GlobalPlugin):
def encode_image(self, image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')

def describe_image(self, file):
base64_image = self.encode_image(file)
headers = {
"Content-Type": "application/json",
"X-Image-Describer-Client": "NVDA",
}
payload = {"srcUrl": f"data:image/jpeg;base64,{base64_image}", "quick": False}
response = requests.post(
"https://describe.accesslint.com/api/v2/descriptions",
headers=headers, json=payload, timeout=15)
result = response.json()
data = json.dumps(payload).encode("utf-8")
request = urllib.request.Request("https://describe.accesslint.com/api/v2/descriptions", method="POST", data=data)
request.add_header('Content-Type', 'application/json')
request.add_header('X-Image-Describer-Client', 'NVDA')
response = urllib.request.urlopen(request, timeout=15).read()
result = json.loads(response.decode("utf-8"))
content = result["description"]
ui.message(content)
os.unlink(file)
Expand Down

0 comments on commit e227964

Please sign in to comment.