Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,15 +4,17 @@ import streamlit as st
|
|
4 |
import webchat
|
5 |
import utils
|
6 |
|
7 |
-
# URL of the hosted LLMs
|
8 |
-
|
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")
|
@@ -30,16 +32,19 @@ def main():
|
|
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
|
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
|
@@ -50,14 +55,14 @@ def main():
|
|
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
|
61 |
|
62 |
# Cleaning Vector Database
|
63 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
|
|
4 |
import webchat
|
5 |
import utils
|
6 |
|
7 |
+
# Default URL of the hosted LLMs
|
8 |
+
default_url = "https://us-south.ml.cloud.ibm.com"
|
9 |
|
10 |
def main():
|
11 |
+
# Initialize session state for credentials and url
|
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 |
+
if 'watsonx_url' not in st.session_state:
|
17 |
+
st.session_state['watsonx_url'] = default_url
|
18 |
|
19 |
st.set_page_config(layout="wide", page_title="RAG Web Demo", page_icon="")
|
20 |
utils.load_css("styles.css")
|
|
|
32 |
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)
|
33 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
34 |
|
35 |
+
# Input fields for API Key, Project ID, and Watsonx URL
|
36 |
api_key_input = st.sidebar.text_input("API Key", st.session_state['api_key'], type="password")
|
37 |
project_id_input = st.sidebar.text_input("Project ID", st.session_state['watsonx_project_id'])
|
38 |
+
watsonx_url_input = st.sidebar.text_input("Watsonx URL", st.session_state['watsonx_url'])
|
39 |
+
|
40 |
# Update session state with the provided credentials
|
41 |
if api_key_input:
|
42 |
st.session_state['api_key'] = api_key_input
|
43 |
if project_id_input:
|
44 |
st.session_state['watsonx_project_id'] = project_id_input
|
45 |
+
if watsonx_url_input:
|
46 |
+
st.session_state['watsonx_url'] = watsonx_url_input
|
47 |
+
|
48 |
# Main input area
|
49 |
user_url = st.text_input('Provide a URL')
|
50 |
# UI component to enter the question
|
|
|
55 |
|
56 |
collection_name = "base"
|
57 |
client = utils.chromadb_client()
|
58 |
+
|
59 |
+
if st.session_state['api_key'] and st.session_state['watsonx_project_id'] and st.session_state['watsonx_url']:
|
60 |
if button_clicked and user_url:
|
61 |
# Invoke the LLM when the button is clicked
|
62 |
+
response = webchat.answer_questions_from_web(st.session_state['api_key'], st.session_state['watsonx_project_id'], user_url, question, collection_name, client, st.session_state['watsonx_url'])
|
63 |
st.write(response)
|
64 |
else:
|
65 |
+
st.warning("Please provide API Key, Project ID, and Watsonx URL in the sidebar.")
|
66 |
|
67 |
# Cleaning Vector Database
|
68 |
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|