ruslanmv commited on
Commit
a83407e
·
1 Parent(s): 35dac1d
Files changed (3) hide show
  1. README.md +1 -3
  2. streamlit_webchat.py → backup/v1/run.py +0 -0
  3. run.py +56 -0
README.md CHANGED
@@ -47,15 +47,13 @@ There are several ways to create an environment in Python. Follow these steps to
47
  Once you have your environment set up and activated, you need to install the necessary libraries. Run the following command to install the required packages:
48
 
49
  ```bash
50
- pip install streamlit python-dotenv ibm_watson_machine_learning requests chromadb
51
  ```
52
 
53
  IMPORTANT: Be aware of the disk space that will be taken up by documents when they're loaded into
54
  chromadb on your laptop. The size in chroma will likely be the same as .txt file size
55
 
56
 
57
-
58
-
59
  ## Step 3: Getting API from IBM Cloud
60
 
61
  ### Obtaining an API Key
 
47
  Once you have your environment set up and activated, you need to install the necessary libraries. Run the following command to install the required packages:
48
 
49
  ```bash
50
+ pip install streamlit python-dotenv ibm_watson_machine_learning requests chromadb sentence_transformers
51
  ```
52
 
53
  IMPORTANT: Be aware of the disk space that will be taken up by documents when they're loaded into
54
  chromadb on your laptop. The size in chroma will likely be the same as .txt file size
55
 
56
 
 
 
57
  ## Step 3: Getting API from IBM Cloud
58
 
59
  ### Obtaining an API Key
streamlit_webchat.py → backup/v1/run.py RENAMED
File without changes
run.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # For reading credentials from the .env file
2
+ import os
3
+ from dotenv import load_dotenv
4
+ import streamlit as st
5
+ import webchat
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
+ # These global variables will be updated in get_credentials() function
11
+ watsonx_project_id = ""
12
+ api_key = ""
13
+
14
+ def get_credentials():
15
+ load_dotenv()
16
+ # Update the global variables that will be used for authentication in another function
17
+ globals()["api_key"] = os.getenv("API_KEY", "")
18
+ globals()["watsonx_project_id"] = os.getenv("PROJECT_ID", "")
19
+
20
+ def main():
21
+ # Get the API key and project id and update global variables
22
+ get_credentials()
23
+
24
+ # Use the full page instead of a narrow central column
25
+ st.set_page_config(layout="wide")
26
+
27
+ # Streamlit app title
28
+ st.title("🌠Demo of RAG with a Web page")
29
+
30
+ # Sidebar for settings
31
+ st.sidebar.header("Settings")
32
+ api_key_input = st.sidebar.text_input("API Key", api_key)
33
+ project_id_input = st.sidebar.text_input("Project ID", watsonx_project_id)
34
+
35
+ # Update credentials if provided by the user
36
+ if api_key_input:
37
+ globals()["api_key"] = api_key_input
38
+ if project_id_input:
39
+ globals()["watsonx_project_id"] = project_id_input
40
+
41
+ user_url = st.text_input('Provide a URL')
42
+ collection_name = st.text_input('Provide a unique name for this website (lower case). Use the same name for the same URL to avoid loading data multiple times.')
43
+
44
+ # UI component to enter the question
45
+ question = st.text_area('Question', height=100)
46
+ button_clicked = st.button("Answer the question")
47
+
48
+ st.subheader("Response")
49
+
50
+ # Invoke the LLM when the button is clicked
51
+ if button_clicked:
52
+ response = webchat.answer_questions_from_web(api_key, watsonx_project_id, user_url, question, collection_name)
53
+ st.write(response)
54
+
55
+ if __name__ == "__main__":
56
+ main()