Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
-
from fastapi.responses import HTMLResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.templating import Jinja2Templates
|
| 5 |
import fitz # PyMuPDF
|
|
@@ -106,15 +106,17 @@ templates = Jinja2Templates(directory="templates")
|
|
| 106 |
async def read_root(request: Request):
|
| 107 |
return templates.TemplateResponse("index.html", {"request": request})
|
| 108 |
|
| 109 |
-
@app.post("/uploadfile/")
|
| 110 |
-
async def upload_file(
|
| 111 |
temp_dir = tempfile.TemporaryDirectory()
|
| 112 |
temp_pdf_path = os.path.join(temp_dir.name, file.filename)
|
| 113 |
with open(temp_pdf_path, "wb") as buffer:
|
| 114 |
buffer.write(await file.read())
|
| 115 |
|
| 116 |
json_output, results = run_GOT(temp_pdf_path)
|
| 117 |
-
print(results)
|
| 118 |
temp_dir.cleanup()
|
| 119 |
|
| 120 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
+
from fastapi.responses import JSONResponse, HTMLResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.templating import Jinja2Templates
|
| 5 |
import fitz # PyMuPDF
|
|
|
|
| 106 |
async def read_root(request: Request):
|
| 107 |
return templates.TemplateResponse("index.html", {"request": request})
|
| 108 |
|
| 109 |
+
@app.post("/uploadfile/", response_class=JSONResponse)
|
| 110 |
+
async def upload_file(file: UploadFile = File(...)):
|
| 111 |
temp_dir = tempfile.TemporaryDirectory()
|
| 112 |
temp_pdf_path = os.path.join(temp_dir.name, file.filename)
|
| 113 |
with open(temp_pdf_path, "wb") as buffer:
|
| 114 |
buffer.write(await file.read())
|
| 115 |
|
| 116 |
json_output, results = run_GOT(temp_pdf_path)
|
|
|
|
| 117 |
temp_dir.cleanup()
|
| 118 |
|
| 119 |
+
return results
|
| 120 |
+
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|