SCapi / app.py
Tanxshh's picture
Update app.py
9b81991 verified
raw
history blame contribute delete
929 Bytes
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")}