refactor: convert get route to post
This commit is contained in:
parent
1466dd0363
commit
3960d106c8
18
src/main.py
18
src/main.py
@ -1,8 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from base64 import b64decode
|
||||||
|
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from pydantic import BaseModel
|
||||||
from doctr.io import DocumentFile
|
from doctr.io import DocumentFile
|
||||||
from doctr.models import ocr_predictor
|
from doctr.models import ocr_predictor
|
||||||
from fastapi import FastAPI, HTTPException, Response
|
from fastapi import FastAPI, HTTPException, Response
|
||||||
@ -45,10 +47,16 @@ def root():
|
|||||||
|
|
||||||
return Response(renderTemplate("main.html", {"results": result}))
|
return Response(renderTemplate("main.html", {"results": result}))
|
||||||
|
|
||||||
|
class Image(BaseModel):
|
||||||
|
file_name: str
|
||||||
|
file_contents: str
|
||||||
|
|
||||||
@app.get("/detect/")
|
@app.post("/detect/")
|
||||||
def file(file_name: str):
|
def file(file: Image):
|
||||||
file_name = os.path.expanduser("~/Projects/sandbox/")+unquote(file_name).lstrip("/")
|
file_name = unquote(file.file_name)
|
||||||
|
|
||||||
|
with open("data/"+file_name, "wb") as f:
|
||||||
|
f.write(b64decode(file.file_contents))
|
||||||
|
|
||||||
print("Working on: " + file_name)
|
print("Working on: " + file_name)
|
||||||
|
|
||||||
@ -60,7 +68,7 @@ def file(file_name: str):
|
|||||||
assume_straight_pages=False,
|
assume_straight_pages=False,
|
||||||
preserve_aspect_ratio=True,
|
preserve_aspect_ratio=True,
|
||||||
)
|
)
|
||||||
doc = DocumentFile.from_images(file_name)
|
doc = DocumentFile.from_images("data/"+file_name)
|
||||||
pred_res = predictor(doc)
|
pred_res = predictor(doc)
|
||||||
json_res = pred_res.export()
|
json_res = pred_res.export()
|
||||||
converted = convert_dict_items_to_list(json_res)
|
converted = convert_dict_items_to_list(json_res)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user