Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,21 @@ def read_root():
|
|
| 17 |
# toolkit = GmailToolkit()
|
| 18 |
return {"message": "Connection"}
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# # API endpoint for prediction
|
| 21 |
# @app.post("/predict")
|
| 22 |
# async def predict_image(file: UploadFile = File(...)):
|
|
|
|
| 17 |
# toolkit = GmailToolkit()
|
| 18 |
return {"message": "Connection"}
|
| 19 |
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
UPLOAD_FOLDER = "uploaded_pdfs"
|
| 23 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 24 |
+
|
| 25 |
+
@app.post("/upload-pdf")
|
| 26 |
+
async def upload_pdf(file: UploadFile = File(...)):
|
| 27 |
+
try:
|
| 28 |
+
file_location = os.path.join(UPLOAD_FOLDER, file.filename)
|
| 29 |
+
with open(file_location, "wb") as buffer:
|
| 30 |
+
shutil.copyfileobj(file.file, buffer)
|
| 31 |
+
return JSONResponse(content={"message": f"Uploaded {file.filename} successfully"}, status_code=200)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 34 |
+
|
| 35 |
# # API endpoint for prediction
|
| 36 |
# @app.post("/predict")
|
| 37 |
# async def predict_image(file: UploadFile = File(...)):
|