Spaces:
Paused
Paused
| 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 | |
| from model_loader import get_model | |
| app = FastAPI() | |
| def startup_event(): | |
| print("Starting application...") | |
| print("Loading model before API becomes ready...") | |
| get_model() | |
| print("Startup complete. API is ready.") | |
| 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> | |
| """ | |
| 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} | |
| return result |