Spaces:
Runtime error
Runtime error
Download script/api.py from whosouravsharma/paper-qa-rag: direct link, hf CLI and curl.
- Browser
- Download file 763 Bytes
-
https://huggingface.co/spaces/whosouravsharma/paper-qa-rag/resolve/main/script/api.py
- Command line
-
hf download hf://spaces/whosouravsharma/paper-qa-rag/script/api.py
-
curl -L -o api.py https://huggingface.co/spaces/whosouravsharma/paper-qa-rag/resolve/main/script/api.py
763 Bytes
| from fastapi import FastAPI, UploadFile, File | |
| import tempfile | |
| from script.ingest import ingest_pdf | |
| from script.graph import build_graph | |
| app = FastAPI() | |
| graph = build_graph() | |
| vectorstore = None | |
| async def upload_pdf(file: UploadFile = File(...)): | |
| global vectorstore | |
| with tempfile.NamedTemporaryFile(delete=False) as tmp: | |
| tmp.write(await file.read()) | |
| tmp_path = tmp.name | |
| vectorstore = ingest_pdf(tmp_path) | |
| return {"status": "PDF ingested"} | |
| async def ask(question: str): | |
| if vectorstore is None: | |
| return {"error": "Upload a PDF first"} | |
| result = graph.invoke({ | |
| "question": question, | |
| "vectorstore": vectorstore | |
| }) | |
| return {"answer": result["answer"]} | |