File size: 929 Bytes
9a7df04
9b81991
9a7df04
 
6b2883d
9b81991
9a7df04
9b81991
9a7df04
9b81991
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
import shutil
import os
from pipeline import run_pipeline
import pandas as pd

app = FastAPI(title="SC API", description="PDF ESG Analysis API")

# Enable CORS for all origins (you can restrict later)
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

UPLOAD_FOLDER = "/app/uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

@app.post("/pdf-upload")
async def pdf_upload(file: UploadFile = File(...)):
    file_path = os.path.join(UPLOAD_FOLDER, file.filename)
    with open(file_path, "wb") as buffer:
        shutil.copyfileobj(file.file, buffer)

    # Run pipeline
    df = run_pipeline(UPLOAD_FOLDER)
    
    # Optional: delete uploaded file after processing
    # os.remove(file_path)

    return {"status": "success", "data": df.to_dict(orient="records")}