testing / api.py
samim2024's picture
Create api.py
f5eeece verified
raw
history blame
544 Bytes
# api.py
from fastapi import FastAPI, UploadFile, File, Form
from model import load_vectorstore, ask_question
import shutil
app = FastAPI()
@app.post("/upload")
async def upload(file: UploadFile = File(...)):
with open("document.pdf", "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
load_vectorstore("document.pdf")
return {"message": "File indexed successfully."}
@app.post("/ask")
async def ask(question: str = Form(...)):
answer = ask_question(question)
return {"question": question, "answer": answer}