File size: 992 Bytes
d4db0fd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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)
|