|
from ArabicOcr import arabicocr |
|
import json |
|
import numpy as np |
|
from io import BytesIO |
|
from PIL import Image |
|
from aiohttp import ClientSession |
|
|
|
async def getImage(img_url): |
|
async with ClientSession() as session: |
|
async with session.get(img_url) as response: |
|
img_data = await response.read() |
|
return BytesIO(img_data) |
|
|
|
async def main_det(image): |
|
try: |
|
|
|
out = "data.jpg" |
|
results=await arabicocr.arabic_ocr(image,"a.jpg") |
|
print(results) |
|
words=[] |
|
for i in range(len(results)): |
|
word=results[i][1] |
|
words.append(word) |
|
return json.dumps({"prediction":words}) |
|
except Exception as e: |
|
raise ValueError(f"Error in main_det: {str(e)}") |
|
|