Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
import shutil
|
| 3 |
+
from inference import process_document
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.get("/")
|
| 8 |
+
def root():
|
| 9 |
+
return {"status": "API running"}
|
| 10 |
+
|
| 11 |
+
@app.post("/extract")
|
| 12 |
+
async def extract(file: UploadFile = File(...)):
|
| 13 |
+
file_path = f"/tmp/{file.filename}"
|
| 14 |
+
|
| 15 |
+
with open(file_path, "wb") as buffer:
|
| 16 |
+
shutil.copyfileobj(file.file, buffer)
|
| 17 |
+
|
| 18 |
+
result = process_document(file_path)
|
| 19 |
+
|
| 20 |
+
return {"result": result}
|