VisLanRAG / src /streamlit_app.py
zach9111's picture
Fix import paths and user permissions for Streamlit
72a3bea
import warnings
warnings.filterwarnings("ignore") # Optional: silence unimportant Streamlit/TF warnings
import streamlit as st
import os
import time
from dotenv import load_dotenv
import sys
import os
sys.path.append(os.path.abspath(".."))
from rag_engine import generate_answer, summarize_document
from pdf_parser import parse_pdf
from pdf_parser import parse_pdf
load_dotenv()
st.set_page_config(page_title="DocSight-RAG πŸ‘οΈπŸ“„", page_icon="πŸ“š")
st.title("DocSight-RAG: Ask Your PDFs")
with st.sidebar:
st.header("Upload PDF")
uploaded_file = st.file_uploader("Choose a PDF", type=["pdf"])
process = st.button("Process PDF")
if uploaded_file and process:
with st.spinner("Processing..."):
with open(uploaded_file.name, "wb") as f:
f.write(uploaded_file.read())
parse_pdf(uploaded_file.name)
st.success("βœ… PDF processed.")
question = st.text_input("Ask something:")
if question:
with st.spinner("Generating answer..."):
start = time.time()
answers = generate_answer(question)
end = time.time()
for ans in answers:
st.subheader(f"πŸ“„ Page {ans['page']}")
st.image(ans["thumbnail"], width=250, caption="Reference Page")
st.write(f"πŸ’¬ **Answer:** {ans['answer']}")
st.info(f"⚑ Answered in {round(end - start, 2)} seconds")
if st.button("πŸ“˜ Summarize Document"):
with st.spinner("Summarizing entire document..."):
summary = summarize_document()
st.subheader("πŸ“˜ Document Summary")
st.write(summary)