File size: 1,714 Bytes
737e9ac
4b41cfa
 
 
 
a1c0614
4b41cfa
 
 
0402ac1
d59d547
4b41cfa
 
 
 
 
 
a704984
a1c0614
a704984
 
 
 
 
 
4b41cfa
 
13b91f3
bf2a56e
037c2d9
0402ac1
682f6e8
63d2f3b
 
2a5defe
13b91f3
737e9ac
ef6452f
13b91f3
36eabbc
5536bb5
13b91f3
 
 
c0365f2
5536bb5
e776846
2a5defe
c0365f2
e776846
a1c0614
4b41cfa
 
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
import os
import streamlit as st
from QA_Bot import QA_Bot
from PDF_Reader import PDF_4_QA
from PIL import Image
from pathlib import Path

# Streamlit app
def main():
    st.session_state.disabled = False 
    st.session_state.visibility = "visible"
    # Page config
    st.set_page_config(page_title="Q&A ChatBot",
                       layout="wide"
                       )

    st.sidebar.title("Upload PDF")
    # st.sidebar.write("Download Demo PDF file from Below....")
    
    # with open("docs/SamarthTandon_cv_2.pdf", "rb") as file:
    #     btn = st.sidebar.download_button(
    #         label="Download PDF",
    #         data=file,
    #         file_name="SamarthTandon_cv_2.pdf"
    #     )

    uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type="pdf")
    
    api_input = st.sidebar.text_input(
        "Enter The API KEY πŸ‘‡",
        label_visibility=st.session_state.visibility,
        disabled=st.session_state.disabled,
        type="password")
    
    if uploaded_file is not None and api_input is not "":
        save_folder = 'docs/'
        if not os.path.isdir(save_folder):
            os.makedirs(save_folder)
        save_path = Path(save_folder, uploaded_file.name)
        print("Save Path :{} , API Input {} iss".format(save_path,api_input))
        
        with open(save_path, mode='wb') as w:
            w.write(uploaded_file.getvalue())
        
        st.sidebar.success("File uploaded successfully",icon="βœ…")

        vector_store , documents = PDF_4_QA(save_path)
        st.sidebar.success("Vector database created successfully",icon="βœ…")
        
        QA_Bot(vector_store,api_input,documents)
    
if __name__ == '__main__':
    main()