Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
from fastapi import FastAPI, File, Request, UploadFile, Body, Depends, HTTPException
|
3 |
from fastapi.security.api_key import APIKeyHeader
|
4 |
from typing import Optional, Annotated
|
@@ -24,17 +25,12 @@ async def ocr(
|
|
24 |
api_key: str = Depends(get_api_key),
|
25 |
image: UploadFile = File(...),
|
26 |
# languages: list = Body(["eng"])
|
27 |
-
# request: Request,
|
28 |
-
# body: dict = Body(...),
|
29 |
):
|
30 |
-
# print("[where?] outside try block")
|
31 |
-
# print("[image]", image)
|
32 |
try:
|
33 |
content = await image.read()
|
34 |
image = Image.open(BytesIO(content))
|
35 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
36 |
text = pytesseract.image_to_string(image, lang = 'eng')
|
37 |
-
# message = "file uploaded"
|
38 |
except Exception as e:
|
39 |
return {"error": str(e)}, 500
|
40 |
|
|
|
1 |
import os
|
2 |
+
os.system("sudo apt-get install tesseract-ocr")
|
3 |
from fastapi import FastAPI, File, Request, UploadFile, Body, Depends, HTTPException
|
4 |
from fastapi.security.api_key import APIKeyHeader
|
5 |
from typing import Optional, Annotated
|
|
|
25 |
api_key: str = Depends(get_api_key),
|
26 |
image: UploadFile = File(...),
|
27 |
# languages: list = Body(["eng"])
|
|
|
|
|
28 |
):
|
|
|
|
|
29 |
try:
|
30 |
content = await image.read()
|
31 |
image = Image.open(BytesIO(content))
|
32 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
33 |
text = pytesseract.image_to_string(image, lang = 'eng')
|
|
|
34 |
except Exception as e:
|
35 |
return {"error": str(e)}, 500
|
36 |
|