File size: 2,089 Bytes
1bdec92
 
 
 
209a678
 
6748f9d
2b87e85
 
 
e9be9df
 
 
c279594
1bdec92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b87e85
 
1bdec92
2b87e85
1bdec92
2b87e85
 
 
1bdec92
2b87e85
 
 
 
 
aa3ec08
 
2b87e85
aa3ec08
 
2b87e85
aa3ec08
 
2b87e85
c552ef8
1bdec92
 
 
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
58
59
60
61
62
63
64
65
66
67
import streamlit as st
from QA_Bot import QA_Bot
from PDF_Reader import PDF_4_QA
from PIL import Image
import cProfile
import pstats
from io import StringIO
import time

def print_time(start, end):
    # Initialize chat history
    if "messages" not in st.session_state:
        st.session_state.messages = []
    st.session_state.messages.append({"role": "assistant", "content": f"Execution time: {end - start} seconds"})

# Streamlit app
def main():
    # Page icon
    icon = Image.open('td-logo.png')

    # Page config
    st.set_page_config(page_title="Q&A ChatBot",
                       page_icon=icon,
                       layout="wide"
                       )

    company_logo_path = 'td-logo.png'
    st.sidebar.image(company_logo_path, width=50)
    st.sidebar.title("Upload PDF")
    st.sidebar.write("Download Demo PDF file from Below....")
    with open("Kia_EV6.pdf", "rb") as file:
        btn = st.sidebar.download_button(
            label="Download PDF",
            data=file,
            file_name="Kia_EV6.pdf"
        )

    uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type="pdf")
    if uploaded_file is not None:
        # profiler = cProfile.Profile()
        # profiler.enable()
        st.sidebar.success("File uploaded successfully.")
        start_time = time.time()
        vector_store = PDF_4_QA(uploaded_file)
        end_time = time.time()
        print_time(start_time, end_time)
        start_time = time.time()
        QA_Bot(vector_store)
        end_time = time.time()
        print_time(start_time, end_time)
        # profiler.disable()
        # s = StringIO()
        # ps = pstats.Stats(profiler, stream=s).sort_stats('cumulative')
        
        # Print the profiling results to the StringIO object
        # ps.print_stats()
        
        # Get the profiling results as a string
        # profiling_results = s.getvalue()
        
        # Print the profiling results
        # st.session_state.messages.append({"role": "assistant", "content": profiling_results})
        

if __name__ == '__main__':
    main()