|
|
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") |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
df = run_pipeline(UPLOAD_FOLDER) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {"status": "success", "data": df.to_dict(orient="records")} |
|
|
|