Update main.py
Browse files
main.py
CHANGED
@@ -23,27 +23,23 @@ def get_api_key(api_key: Optional[str] = Depends(api_key_header)):
|
|
23 |
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 |
-
|
34 |
-
|
35 |
-
# # image = Image.open(file.file)
|
36 |
-
# print("[content]",content)
|
37 |
-
# image = Image.open(BytesIO(content))
|
38 |
-
# print("[image]",image)
|
39 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
40 |
-
|
41 |
-
message = "file uploaded"
|
42 |
except Exception as e:
|
43 |
return {"error": str(e)}, 500
|
44 |
|
45 |
# return jsonable_encoder({"text": text})
|
46 |
-
return {"
|
47 |
|
48 |
@app.post("/api/translate", response_model=dict)
|
49 |
async def translate(
|
|
|
23 |
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)
|
37 |
+
# message = "file uploaded"
|
38 |
except Exception as e:
|
39 |
return {"error": str(e)}, 500
|
40 |
|
41 |
# return jsonable_encoder({"text": text})
|
42 |
+
return {"ImageText": text}
|
43 |
|
44 |
@app.post("/api/translate", response_model=dict)
|
45 |
async def translate(
|