import streamlit as st from model import load_vectorstore, ask_question import os st.set_page_config(page_title="RAG with Mistral AI", layout="centered") st.title("RAG Q&A App with Mistral AI") st.write("Upload a document and ask questions about it.") uploaded_file = st.file_uploader("Upload PDF", type=["pdf"]) if uploaded_file: with open("document.pdf", "wb") as f: f.write(uploaded_file.read()) st.success("File uploaded!") if st.button("Index Document"): with st.spinner("Processing..."): load_vectorstore("document.pdf") st.success("Vectorstore ready.") query = st.text_input("Enter your question") if st.button("Ask") and query: with st.spinner("Generating answer..."): answer = ask_question(query) st.write("**Answer:**", answer) # 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}