Update main.py
Browse files
main.py
CHANGED
|
@@ -12,8 +12,8 @@ app = FastAPI(
|
|
| 12 |
|
| 13 |
# Global in-memory state
|
| 14 |
global_state = {
|
| 15 |
-
"vectorstore":
|
| 16 |
-
"rag_chain":
|
| 17 |
}
|
| 18 |
|
| 19 |
@app.get("/")
|
|
@@ -27,24 +27,4 @@ def ask(prompt: str):
|
|
| 27 |
return JSONResponse(status_code=400, content={"error": "Please upload and process a PDF first."})
|
| 28 |
|
| 29 |
answer = get_response(global_state["rag_chain"], global_state["vectorstore"], prompt)
|
| 30 |
-
return {"question": prompt, "answer": answer}
|
| 31 |
-
|
| 32 |
-
# @app.post("/upload/")
|
| 33 |
-
# async def upload_pdf(file: UploadFile = File(...)):
|
| 34 |
-
# """Endpoint to upload and process a PDF file."""
|
| 35 |
-
# # Save PDF temporarily
|
| 36 |
-
# with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
|
| 37 |
-
# tmp_file_path = tmp.name
|
| 38 |
-
# shutil.copyfileobj(file.file, tmp)
|
| 39 |
-
|
| 40 |
-
# try:
|
| 41 |
-
# chunks = load_and_process_pdf(tmp_file_path)
|
| 42 |
-
# vectorstore = create_vectorstore(chunks)
|
| 43 |
-
# rag_chain = create_rag_chain()
|
| 44 |
-
|
| 45 |
-
# global_state["vectorstore"] = vectorstore
|
| 46 |
-
# global_state["rag_chain"] = rag_chain
|
| 47 |
-
|
| 48 |
-
# return {"message": "PDF processed successfully", "filename": file.filename}
|
| 49 |
-
# finally:
|
| 50 |
-
# os.unlink(tmp_file_path)
|
|
|
|
| 12 |
|
| 13 |
# Global in-memory state
|
| 14 |
global_state = {
|
| 15 |
+
"vectorstore": create_vectorstore(),
|
| 16 |
+
"rag_chain": create_rag_chain()
|
| 17 |
}
|
| 18 |
|
| 19 |
@app.get("/")
|
|
|
|
| 27 |
return JSONResponse(status_code=400, content={"error": "Please upload and process a PDF first."})
|
| 28 |
|
| 29 |
answer = get_response(global_state["rag_chain"], global_state["vectorstore"], prompt)
|
| 30 |
+
return {"question": prompt, "answer": answer}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|