File size: 1,140 Bytes
92b81d7
679a94f
92b81d7
 
2e2d0cc
c477faa
92b81d7
 
 
c477faa
 
 
 
 
 
 
679a94f
92b81d7
679a94f
 
 
 
 
 
 
 
 
 
 
 
92b81d7
 
 
 
 
 
 
 
4f5516a
 
92b81d7
a81660d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()

@app.on_event("startup")
def startup_event():
    print("Starting application...")
    print("Loading model before API becomes ready...")
    get_model()
    print("Startup complete. API is ready.")

@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}
    return result