Experiments / app.py
credent007's picture
add process_whole_doc fun in app.py
58e5e7c verified
# from fastapi import FastAPI, UploadFile, File
# import shutil
# from inference import process_document
# app = FastAPI()
# @app.get("/")
# def root():
# return {"status": "API running"}
# @app.post("/extract")
# async def extract(file: UploadFile = File(...)):
# file_path = f"/tmp/{file.filename}"
# with open(file_path, "wb") as buffer:
# shutil.copyfileobj(file.file, buffer)
# result = process_document(file_path)
# return {"result": result}
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import HTMLResponse
import shutil
from inference import process_document
from json_handling import process_whole_doc
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
def root():
return """
<html>
<head>
<title>Qwen Extraction API</title>
</head>
<body>
<h2>✅ Qwen Extraction API Running</h2>
<p>Use POST /extract to upload file</p>
<a href="/docs">Go to API Docs</a>
</body>
</html>
"""
@app.post("/extract")
async def extract(file: UploadFile = File(...)):
file_path = f"/tmp/{file.filename}"
with open(file_path, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
# result = process_document(file_path)
result = process_whole_doc(file_path)
return {"result": result}