File size: 3,290 Bytes
a0cdb9e cd496dd a65b65e 2f3ee19 a65b65e 2f3ee19 a0cdb9e 2e2b471 a0cdb9e 2e2b471 a0cdb9e 2f3ee19 a0cdb9e 625431b a0cdb9e 625431b a0cdb9e 625431b a0cdb9e 625431b a0cdb9e 625431b a0cdb9e 625431b 2e2b471 625431b a0cdb9e 625431b a0cdb9e 2f3ee19 a0cdb9e 2f3ee19 a0cdb9e 2f3ee19 2e2b471 2f3ee19 a0cdb9e 2f3ee19 a0cdb9e 2f3ee19 a0cdb9e 2f3ee19 |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import streamlit as st
from utils import *
import constants
import os
import base64
def get_base64(bin_file):
with open(bin_file, 'rb') as f:
data = f.read()
return base64.b64encode(data).decode()
def set_background(png_file):
bin_str = get_base64(png_file)
page_bg_img = '''
<style>
.stApp {
background-image: url("data:img.jpg;base64,%s");
background-size: cover;
}
</style>
''' % bin_str
st.markdown(page_bg_img, unsafe_allow_html=True)
st.set_page_config(
page_title="TCE Chat Bot",
initial_sidebar_state="collapsed"
)
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
.stDeployButton {display:none;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
set_background('./15683.jpg')
if 'HuggingFace_API_Key' not in st.session_state:
st.session_state['HuggingFace_API_Key'] = os.environ["HF_TOKEN"]
if 'Pinecone_API_Key' not in st.session_state:
st.session_state['Pinecone_API_Key'] = os.environ["PINECONE_API"]
st.title("π TCE.edu Chat Assistant: Your Friendly Guide to Everything TCE! π")
st.sidebar.title("ποΈ")
load_button = st.sidebar.button("Load data to Pinecone", key="load_button")
if load_button:
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
site_data=get_website_data(constants.WEBSITE_URL)
st.write("β
Data fetched successfully!")
chunks_data=split_data(site_data)
st.write("βοΈ Data split into manageable parts!")
embeddings=create_embeddings()
st.write("π§ Model ready to understand your queries!")
push_to_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings,chunks_data)
st.write("π Data loaded into Pinecone for quick searching!")
st.sidebar.success("π Data successfully loaded into Pinecone!")
else:
st.sidebar.error("β Oops! Please provide your API keys.")
prompt = st.text_input('How can I help you today β',key="prompt")
document_count = st.slider('Number of results to show π - (0 LOW || 5 HIGH)', 0, 5, 2,step=1)
submit = st.button("Ask! π")
if submit:
if st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_API_Key']!="" :
embeddings=create_embeddings()
st.write("π§ Model ready to understand your queries!")
index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],constants.PINECONE_ENVIRONMENT,constants.PINECONE_INDEX,embeddings)
st.write("π Database retrieval is done!")
relavant_docs=get_similar_docs(index,prompt,document_count)
#st.write(relavant_docs)
st.success("π Here are the search results:")
st.write("π List of search results:")
for document in relavant_docs:
st.write("π**Result : "+ str(relavant_docs.index(document)+1) + "**")
st.write("**Info:**: "+document.page_content)
st.write("π **Link**: "+ document.metadata['source'])
else:
st.sidebar.error("β Oops! Please provide your API keys.") |