Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,34 +3,43 @@ from dotenv import load_dotenv
|
|
3 |
import streamlit as st
|
4 |
import webchat
|
5 |
import utils
|
|
|
6 |
# URL of the hosted LLMs is hardcoded because at this time all LLMs share the same endpoint
|
7 |
url = "https://us-south.ml.cloud.ibm.com"
|
8 |
-
|
9 |
-
watsonx_project_id = ""
|
10 |
-
api_key = ""
|
11 |
def main():
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
st.set_page_config(layout="wide", page_title="RAG Web Demo", page_icon="")
|
14 |
utils.load_css("styles.css")
|
|
|
15 |
# Streamlit app title with style
|
16 |
st.markdown("""
|
17 |
<div class="menu-bar">
|
18 |
<h1>IBM watsonx.ai - webchat</h1>
|
19 |
</div>
|
20 |
<div style="margin-top: 20px;"><p>Insert the website you want to chat with and ask your question.</p></div>
|
21 |
-
|
22 |
""", unsafe_allow_html=True)
|
|
|
23 |
# Sidebar for settings
|
24 |
st.sidebar.header("Settings")
|
25 |
-
st.sidebar.markdown("Insert your credentials of [IBM Cloud](https://cloud.ibm.com/login) for watsonx.ai \n The data is not saved
|
26 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
if api_key_input:
|
31 |
-
|
32 |
if project_id_input:
|
33 |
-
|
|
|
34 |
# Main input area
|
35 |
user_url = st.text_input('Provide a URL')
|
36 |
# UI component to enter the question
|
@@ -38,14 +47,14 @@ def main():
|
|
38 |
button_clicked = st.button("Answer the question")
|
39 |
st.markdown("<hr>", unsafe_allow_html=True)
|
40 |
st.subheader("Response")
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
if button_clicked and user_url:
|
47 |
# Invoke the LLM when the button is clicked
|
48 |
-
response = webchat.answer_questions_from_web(api_key, watsonx_project_id, user_url, question, collection_name,client)
|
49 |
st.write(response)
|
50 |
else:
|
51 |
st.warning("Please provide API Key and Project ID in the sidebar.")
|
@@ -54,8 +63,8 @@ def main():
|
|
54 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
55 |
st.sidebar.header("Memory")
|
56 |
clean_button_clicked = st.sidebar.button("Clean Memory")
|
57 |
-
if clean_button_clicked
|
58 |
-
if collection_name:
|
59 |
utils.clear_collection(collection_name, client)
|
60 |
st.sidebar.success("Memory cleared successfully!")
|
61 |
print("Memory cleared successfully!")
|
|
|
3 |
import streamlit as st
|
4 |
import webchat
|
5 |
import utils
|
6 |
+
|
7 |
# URL of the hosted LLMs is hardcoded because at this time all LLMs share the same endpoint
|
8 |
url = "https://us-south.ml.cloud.ibm.com"
|
9 |
+
|
|
|
|
|
10 |
def main():
|
11 |
+
# Initialize session state for credentials
|
12 |
+
if 'watsonx_project_id' not in st.session_state:
|
13 |
+
st.session_state['watsonx_project_id'] = ""
|
14 |
+
if 'api_key' not in st.session_state:
|
15 |
+
st.session_state['api_key'] = ""
|
16 |
+
|
17 |
st.set_page_config(layout="wide", page_title="RAG Web Demo", page_icon="")
|
18 |
utils.load_css("styles.css")
|
19 |
+
|
20 |
# Streamlit app title with style
|
21 |
st.markdown("""
|
22 |
<div class="menu-bar">
|
23 |
<h1>IBM watsonx.ai - webchat</h1>
|
24 |
</div>
|
25 |
<div style="margin-top: 20px;"><p>Insert the website you want to chat with and ask your question.</p></div>
|
|
|
26 |
""", unsafe_allow_html=True)
|
27 |
+
|
28 |
# Sidebar for settings
|
29 |
st.sidebar.header("Settings")
|
30 |
+
st.sidebar.markdown("Insert your credentials of [IBM Cloud](https://cloud.ibm.com/login) for watsonx.ai \n The data is not saved in the server. Your data is secured.", unsafe_allow_html=True)
|
31 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
32 |
+
|
33 |
+
# Input fields for API Key and Project ID
|
34 |
+
api_key_input = st.sidebar.text_input("API Key", st.session_state['api_key'], type="password")
|
35 |
+
project_id_input = st.sidebar.text_input("Project ID", st.session_state['watsonx_project_id'])
|
36 |
+
|
37 |
+
# Update session state with the provided credentials
|
38 |
if api_key_input:
|
39 |
+
st.session_state['api_key'] = api_key_input
|
40 |
if project_id_input:
|
41 |
+
st.session_state['watsonx_project_id'] = project_id_input
|
42 |
+
|
43 |
# Main input area
|
44 |
user_url = st.text_input('Provide a URL')
|
45 |
# UI component to enter the question
|
|
|
47 |
button_clicked = st.button("Answer the question")
|
48 |
st.markdown("<hr>", unsafe_allow_html=True)
|
49 |
st.subheader("Response")
|
50 |
+
|
51 |
+
collection_name = "base"
|
52 |
+
client = utils.chromadb_client()
|
53 |
+
|
54 |
+
if st.session_state['api_key'] and st.session_state['watsonx_project_id']:
|
55 |
if button_clicked and user_url:
|
56 |
# Invoke the LLM when the button is clicked
|
57 |
+
response = webchat.answer_questions_from_web(st.session_state['api_key'], st.session_state['watsonx_project_id'], user_url, question, collection_name, client)
|
58 |
st.write(response)
|
59 |
else:
|
60 |
st.warning("Please provide API Key and Project ID in the sidebar.")
|
|
|
63 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
64 |
st.sidebar.header("Memory")
|
65 |
clean_button_clicked = st.sidebar.button("Clean Memory")
|
66 |
+
if clean_button_clicked:
|
67 |
+
if collection_name:
|
68 |
utils.clear_collection(collection_name, client)
|
69 |
st.sidebar.success("Memory cleared successfully!")
|
70 |
print("Memory cleared successfully!")
|