Update app.py
Browse files
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 |
-
|
| 26 |
-
|
| 27 |
)
|
| 28 |
|
| 29 |
hide_streamlit_style = """
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
if 'HuggingFace_API_Key' not in st.session_state:
|
| 40 |
-
st.session_state['HuggingFace_API_Key'] = os.environ
|
| 41 |
if 'Pinecone_API_Key' not in st.session_state:
|
| 42 |
-
st.session_state['Pinecone_API_Key'] = os.environ
|
| 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 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 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 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 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.")
|