Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -27,22 +27,15 @@ async def ocr(
|
|
27 |
image: UploadFile = File(...),
|
28 |
# languages: list = Body(["eng"])
|
29 |
):
|
30 |
-
|
31 |
try:
|
32 |
content = await image.read()
|
33 |
image = Image.open(BytesIO(content))
|
34 |
-
|
35 |
-
if hasattr(pytesseract, "image_to_string"):
|
36 |
-
print("Image to string function is available")
|
37 |
-
print(pytesseract.image_to_string(image, lang = 'eng'))
|
38 |
-
text = ocr_tesseract(image, ['eng'])
|
39 |
-
else:
|
40 |
-
print("Image to string function is not available")
|
41 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
42 |
except Exception as e:
|
43 |
return {"error": str(e)}, 500
|
44 |
|
45 |
-
return {"ImageText":
|
46 |
|
47 |
@app.post("/api/translate", response_model=dict)
|
48 |
async def translate(
|
@@ -51,8 +44,6 @@ async def translate(
|
|
51 |
src: str = "en",
|
52 |
trg: str = "zh",
|
53 |
):
|
54 |
-
if api_key != API_KEY:
|
55 |
-
return {"error": "Invalid API key"}, 401
|
56 |
|
57 |
tokenizer, model = get_model(src, trg)
|
58 |
|
|
|
27 |
image: UploadFile = File(...),
|
28 |
# languages: list = Body(["eng"])
|
29 |
):
|
|
|
30 |
try:
|
31 |
content = await image.read()
|
32 |
image = Image.open(BytesIO(content))
|
33 |
+
text = pytesseract.image_to_string(image, lang = 'eng')
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
35 |
except Exception as e:
|
36 |
return {"error": str(e)}, 500
|
37 |
|
38 |
+
return {"ImageText": text}
|
39 |
|
40 |
@app.post("/api/translate", response_model=dict)
|
41 |
async def translate(
|
|
|
44 |
src: str = "en",
|
45 |
trg: str = "zh",
|
46 |
):
|
|
|
|
|
47 |
|
48 |
tokenizer, model = get_model(src, trg)
|
49 |
|