Update main.py
Browse files
main.py
CHANGED
@@ -21,25 +21,29 @@ def get_api_key(api_key: Optional[str] = Depends(api_key_header)):
|
|
21 |
|
22 |
@app.post("/api/ocr", response_model=dict)
|
23 |
async def ocr(
|
24 |
-
#
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
):
|
28 |
-
print("[where?] outside try block")
|
29 |
-
print("[image]", image)
|
30 |
try:
|
31 |
-
print("[where?] inside try block")
|
32 |
-
content = await image.read()
|
33 |
-
# image = Image.open(file.file)
|
34 |
-
print("[content]",content)
|
35 |
-
image = Image.open(BytesIO(content))
|
36 |
-
print("[image]",image)
|
37 |
-
text = pytesseract.image_to_string(image, lang="+".join(languages))
|
38 |
-
print("[text]",text)
|
|
|
39 |
except Exception as e:
|
40 |
return {"error": str(e)}, 500
|
41 |
|
42 |
-
return jsonable_encoder({"text": text})
|
|
|
43 |
|
44 |
@app.post("/api/translate", response_model=dict)
|
45 |
async def translate(
|
|
|
21 |
|
22 |
@app.post("/api/ocr", response_model=dict)
|
23 |
async def ocr(
|
24 |
+
# image: UploadFile = File(...),
|
25 |
+
# languages: list = Body(["eng"])
|
26 |
+
request: Request,
|
27 |
+
body: dict = Body(...),
|
28 |
+
api_key: str = Depends(get_api_key),
|
29 |
):
|
30 |
+
# print("[where?] outside try block")
|
31 |
+
# print("[image]", image)
|
32 |
try:
|
33 |
+
# print("[where?] inside try block")
|
34 |
+
# content = await image.read()
|
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 |
+
# print("[text]",text)
|
41 |
+
message = body.get("message", "")
|
42 |
except Exception as e:
|
43 |
return {"error": str(e)}, 500
|
44 |
|
45 |
+
# return jsonable_encoder({"text": text})
|
46 |
+
return {"messageDetails": message}
|
47 |
|
48 |
@app.post("/api/translate", response_model=dict)
|
49 |
async def translate(
|