pdfQA / app.py
engrtm's picture
Upload 5 files
d4db0fd verified
Raw History Blame Contribute Delete
992 Bytes
import streamlit as st
from pdf_reader import extract_text_from_pdf
from qa_utils import split_text, create_vector_store, answer_question
st.set_page_config(page_title="📄 PDF Q&A App")
st.title("📄 Ask Questions from PDF")
# Upload PDF
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
# Load and process PDF
if uploaded_file and "vectorstore" not in st.session_state:
with st.spinner("Reading and processing the PDF..."):
text = extract_text_from_pdf(uploaded_file)
chunks = split_text(text)
vectorstore = create_vector_store(chunks)
st.session_state.vectorstore = vectorstore
st.success("✅ PDF loaded and ready for questions!")
# Ask questions
if "vectorstore" in st.session_state:
query = st.text_input("Ask a question about the PDF:")
if query:
with st.spinner("Generating answer..."):
answer = answer_question(st.session_state.vectorstore, query)
st.write("**Answer:**", answer)