generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (23 loc) · 764 Bytes
/
main.py
File metadata and controls
34 lines (23 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from io import BytesIO
import cv2
import numpy as np
import uvicorn
from fastapi import FastAPI, File, UploadFile
from PIL import Image
from SentenceDetection import underlined_sentences
app = FastAPI()
@app.get("/test")
async def testing():
return "Hello World"
@app.post("/predict/image")
async def predict_api(file: UploadFile = File(...)):
extension = file.filename.split(".")[-1] in ("jpg", "jpeg", "png", "JPG")
if not extension:
return {"Error": "Image must be jpg or png format!"}
image = await file.read()
nparr = np.fromstring(image, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
sentences = underlined_sentences(img)
return sentences
if __name__ == "__main__":
uvicorn.run(app, debug=True)