Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 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
|
| 5 |
from fastapi.encoders import jsonable_encoder
|
| 6 |
from PIL import Image
|
| 7 |
from io import BytesIO
|
|
@@ -21,10 +21,11 @@ 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 |
# 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")
|
|
@@ -38,12 +39,12 @@ async def ocr(
|
|
| 38 |
# print("[image]",image)
|
| 39 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
| 40 |
# print("[text]",text)
|
| 41 |
-
|
| 42 |
except Exception as e:
|
| 43 |
return {"error": str(e)}, 500
|
| 44 |
|
| 45 |
# return jsonable_encoder({"text": text})
|
| 46 |
-
return {"messageDetails":
|
| 47 |
|
| 48 |
@app.post("/api/translate", response_model=dict)
|
| 49 |
async def translate(
|
|
|
|
| 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
|
| 5 |
from fastapi.encoders import jsonable_encoder
|
| 6 |
from PIL import Image
|
| 7 |
from io import BytesIO
|
|
|
|
| 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 |
+
message: Annotated[str, Form()],
|
| 29 |
api_key: str = Depends(get_api_key),
|
| 30 |
):
|
| 31 |
# print("[where?] outside try block")
|
|
|
|
| 39 |
# print("[image]",image)
|
| 40 |
# text = pytesseract.image_to_string(image, lang="+".join(languages))
|
| 41 |
# print("[text]",text)
|
| 42 |
+
receivedMessage = message
|
| 43 |
except Exception as e:
|
| 44 |
return {"error": str(e)}, 500
|
| 45 |
|
| 46 |
# return jsonable_encoder({"text": text})
|
| 47 |
+
return {"messageDetails": receivedMessage}
|
| 48 |
|
| 49 |
@app.post("/api/translate", response_model=dict)
|
| 50 |
async def translate(
|