File size: 1,586 Bytes
905af90
 
 
 
7b952f4
 
 
 
 
b0e2661
 
 
 
905af90
b0e2661
7b952f4
 
72a3bea
 
7b952f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905af90
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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)