Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,33 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
|
|
|
| 2 |
import shutil
|
| 3 |
import os
|
| 4 |
-
import tempfile
|
| 5 |
from pipeline import run_pipeline
|
|
|
|
| 6 |
|
| 7 |
-
app = FastAPI()
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import shutil
|
| 4 |
import os
|
|
|
|
| 5 |
from pipeline import run_pipeline
|
| 6 |
+
import pandas as pd
|
| 7 |
|
| 8 |
+
app = FastAPI(title="SC API", description="PDF ESG Analysis API")
|
| 9 |
|
| 10 |
+
# Enable CORS for all origins (you can restrict later)
|
| 11 |
+
app.add_middleware(
|
| 12 |
+
CORSMiddleware,
|
| 13 |
+
allow_origins=["*"],
|
| 14 |
+
allow_methods=["*"],
|
| 15 |
+
allow_headers=["*"],
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
UPLOAD_FOLDER = "/app/uploads"
|
| 19 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 20 |
+
|
| 21 |
+
@app.post("/pdf-upload")
|
| 22 |
+
async def pdf_upload(file: UploadFile = File(...)):
|
| 23 |
+
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
| 24 |
+
with open(file_path, "wb") as buffer:
|
| 25 |
+
shutil.copyfileobj(file.file, buffer)
|
| 26 |
+
|
| 27 |
+
# Run pipeline
|
| 28 |
+
df = run_pipeline(UPLOAD_FOLDER)
|
| 29 |
+
|
| 30 |
+
# Optional: delete uploaded file after processing
|
| 31 |
+
# os.remove(file_path)
|
| 32 |
+
|
| 33 |
+
return {"status": "success", "data": df.to_dict(orient="records")}
|