Guru-25 commited on
Commit
1591297
Β·
verified Β·
1 Parent(s): 43d8209

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -48
app.py CHANGED
@@ -22,72 +22,67 @@ def set_background(png_file):
22
  st.markdown(page_bg_img, unsafe_allow_html=True)
23
 
24
  st.set_page_config(
25
- page_title="TCE Chat Bot",
26
- initial_sidebar_state="collapsed"
27
  )
28
 
29
  hide_streamlit_style = """
30
- <style>
31
- #MainMenu {visibility: hidden;}
32
- .stDeployButton {display:none;}
33
- footer {visibility: hidden;}
34
- </style>
35
- """
36
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
37
- set_background('./15683.jpg')
 
 
 
 
38
 
39
  if 'HuggingFace_API_Key' not in st.session_state:
40
- st.session_state['HuggingFace_API_Key'] = os.environ["HF_TOKEN"]
41
  if 'Pinecone_API_Key' not in st.session_state:
42
- st.session_state['Pinecone_API_Key'] = os.environ["PINECONE_API"]
43
 
44
- st.title("🌐 TCE.edu Chat Assistant: Your Friendly Guide to Everything TCE! πŸš€")
45
 
46
  st.sidebar.title("πŸ—οΈ")
47
-
48
  load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
49
 
50
  if load_button:
51
- if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
52
-
53
- site_data=get_website_data(constants.WEBSITE_URL)
54
- st.write("βœ… Data fetched successfully!")
55
-
56
- chunks_data=split_data(site_data)
57
- st.write("βœ‚οΈ Data split into manageable parts!")
58
-
59
- embeddings=create_embeddings()
60
- st.write("🧠 Model ready to understand your queries!")
61
- push_to_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings,chunks_data)
62
- st.write("πŸš€ Data loaded into Pinecone for quick searching!")
63
-
64
- st.sidebar.success("πŸŽ‰ Data successfully loaded into Pinecone!")
65
  else:
66
  st.sidebar.error("❌ Oops! Please provide your API keys.")
67
 
68
- prompt = st.text_input('How can I help you today ❓',key="prompt")
69
- document_count = st.slider('Number of results to show πŸ”— - (0 LOW || 5 HIGH)', 0, 5, 2,step=1)
70
-
71
- submit = st.button("Ask! πŸ”")
72
-
73
 
74
  if submit:
75
- if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
76
-
77
- embeddings=create_embeddings()
78
- st.write("🧠 Model ready to understand your queries!")
79
- index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings)
80
- st.write("πŸ” Database retrieval is done!")
81
-
82
- relavant_docs=get_similar_docs(index,prompt,document_count)
83
- #st.write(relavant_docs)
84
-
85
- st.success("πŸŽ‰ Here are the search results:")
86
- st.write("πŸ“œ List of search results:")
87
- for document in relavant_docs:
88
- st.write("πŸ‘‰**Result : "+ str(relavant_docs.index(document)+1) + "**")
89
- st.write("**Info:**: "+document.page_content)
90
- st.write("πŸ”— **Link**: "+ document.metadata['source'])
91
 
 
 
 
 
 
 
92
  else:
93
  st.sidebar.error("❌ Oops! Please provide your API keys.")
 
22
  st.markdown(page_bg_img, unsafe_allow_html=True)
23
 
24
  st.set_page_config(
25
+ page_title="TCE Chat Bot",
26
+ initial_sidebar_state="collapsed"
27
  )
28
 
29
  hide_streamlit_style = """
30
+ <style>
31
+ #MainMenu {visibility: hidden;}
32
+ .stDeployButton {display:none;}
33
+ footer {visibility: hidden;}
34
+ </style>
35
+ """
36
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
37
+
38
+ try:
39
+ set_background('./15683.jpg')
40
+ except:
41
+ st.warning("Background image not found, using default background.")
42
 
43
  if 'HuggingFace_API_Key' not in st.session_state:
44
+ st.session_state['HuggingFace_API_Key'] = os.environ.get("HF_TOKEN", "")
45
  if 'Pinecone_API_Key' not in st.session_state:
46
+ st.session_state['Pinecone_API_Key'] = os.environ.get("PINECONE_API", "")
47
 
48
+ st.title("🌐 TCE.edu Chat Assistant: Your Friendly Guide to Everything TCE! πŸš€")
49
 
50
  st.sidebar.title("πŸ—οΈ")
 
51
  load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
52
 
53
  if load_button:
54
+ if st.session_state['HuggingFace_API_Key'] != "" and st.session_state['Pinecone_API_Key'] != "":
55
+ with st.spinner("Loading data..."):
56
+ site_data = get_website_data(constants.WEBSITE_URL)
57
+ st.write("βœ… Data fetched successfully!")
58
+ chunks_data = split_data(site_data)
59
+ st.write("βœ‚οΈ Data split into manageable parts!")
60
+ embeddings = create_embeddings()
61
+ st.write("🧠 Model ready to understand your queries!")
62
+ push_to_pinecone(st.session_state['Pinecone_API_Key'], constants.PINECONE_INDEX, embeddings, chunks_data)
63
+ st.write("πŸš€ Data loaded into Pinecone for quick searching!")
64
+ st.sidebar.success("πŸŽ‰ Data successfully loaded into Pinecone!")
 
 
 
65
  else:
66
  st.sidebar.error("❌ Oops! Please provide your API keys.")
67
 
68
+ prompt = st.text_input('How can I help you today ❓', key="prompt")
69
+ document_count = st.slider('Number of results to show πŸ”— - (0 LOW || 5 HIGH)', 0, 5, 2, step=1)
70
+ submit = st.button("Ask! πŸ”")
 
 
71
 
72
  if submit:
73
+ if st.session_state['HuggingFace_API_Key'] != "" and st.session_state['Pinecone_API_Key'] != "":
74
+ with st.spinner("Processing your query..."):
75
+ embeddings = create_embeddings()
76
+ st.write("🧠 Model ready to understand your queries!")
77
+ index = pull_from_pinecone(st.session_state['Pinecone_API_Key'], constants.PINECONE_INDEX, embeddings)
78
+ st.write("πŸ” Database retrieval is done!")
79
+ relavant_docs = get_similar_docs(index, prompt, document_count)
 
 
 
 
 
 
 
 
 
80
 
81
+ st.success("πŸŽ‰ Here are the search results:")
82
+ st.write("πŸ“œ List of search results:")
83
+ for document in relavant_docs:
84
+ st.write("πŸ‘‰**Result : " + str(relavant_docs.index(document)+1) + "**")
85
+ st.write("**Info:**: " + document.page_content)
86
+ st.write("πŸ”— **Link**: " + document.metadata['source'])
87
  else:
88
  st.sidebar.error("❌ Oops! Please provide your API keys.")