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 pathlib
|
||||
from fastapi.responses import JSONResponse
|
||||
import numpy as np
|
||||
from base64 import b64decode
|
||||
|
||||
from fastapi.responses import JSONResponse
|
||||
from pydantic import BaseModel
|
||||
from doctr.io import DocumentFile
|
||||
from doctr.models import ocr_predictor
|
||||
from fastapi import FastAPI, HTTPException, Response
|
||||
@ -45,10 +47,16 @@ def root():
|
||||
|
||||
return Response(renderTemplate("main.html", {"results": result}))
|
||||
|
||||
class Image(BaseModel):
|
||||
file_name: str
|
||||
file_contents: str
|
||||
|
||||
@app.get("/detect/")
|
||||
def file(file_name: str):
|
||||
file_name = os.path.expanduser("~/Projects/sandbox/")+unquote(file_name).lstrip("/")
|
||||
@app.post("/detect/")
|
||||
def file(file: Image):
|
||||
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)
|
||||
|
||||
@ -60,7 +68,7 @@ def file(file_name: str):
|
||||
assume_straight_pages=False,
|
||||
preserve_aspect_ratio=True,
|
||||
)
|
||||
doc = DocumentFile.from_images(file_name)
|
||||
doc = DocumentFile.from_images("data/"+file_name)
|
||||
pred_res = predictor(doc)
|
||||
json_res = pred_res.export()
|
||||
converted = convert_dict_items_to_list(json_res)
|
||||
|
Loading…
x
Reference in New Issue
Block a user