|
|
import warnings |
|
|
warnings.filterwarnings("ignore") |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|