Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,17 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
| 2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import shutil
|
| 4 |
import os
|
| 5 |
import tempfile
|
| 6 |
-
from pipeline import run_pipeline
|
| 7 |
|
| 8 |
-
app = FastAPI(
|
| 9 |
-
|
| 10 |
-
# Allow CORS so your website or n8n can POST
|
| 11 |
-
app.add_middleware(
|
| 12 |
-
CORSMiddleware,
|
| 13 |
-
allow_origins=["*"], # You can restrict to your website
|
| 14 |
-
allow_credentials=True,
|
| 15 |
-
allow_methods=["*"],
|
| 16 |
-
allow_headers=["*"],
|
| 17 |
-
)
|
| 18 |
|
| 19 |
@app.post("/upload_pdf")
|
| 20 |
async def upload_pdf(files: list[UploadFile] = File(...)):
|
| 21 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 22 |
-
pdf_paths = []
|
| 23 |
for file in files:
|
| 24 |
dest = os.path.join(tmpdirname, file.filename)
|
| 25 |
with open(dest, "wb") as f:
|
| 26 |
shutil.copyfileobj(file.file, f)
|
| 27 |
-
pdf_paths.append(dest)
|
| 28 |
-
|
| 29 |
-
# Run the SC pipeline
|
| 30 |
results = run_pipeline(tmpdirname)
|
| 31 |
return results.to_dict(orient="records")
|
|
|
|
| 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 |
@app.post("/upload_pdf")
|
| 10 |
async def upload_pdf(files: list[UploadFile] = File(...)):
|
| 11 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
|
|
| 12 |
for file in files:
|
| 13 |
dest = os.path.join(tmpdirname, file.filename)
|
| 14 |
with open(dest, "wb") as f:
|
| 15 |
shutil.copyfileobj(file.file, f)
|
|
|
|
|
|
|
|
|
|
| 16 |
results = run_pipeline(tmpdirname)
|
| 17 |
return results.to_dict(orient="records")
|