-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import streamlit as st | ||
from streamlit_chat import message | ||
from streamlit_extras.colored_header import colored_header | ||
from streamlit_extras.add_vertical_space import add_vertical_space | ||
from hugchat import hugchat | ||
|
||
st.set_page_config(page_title="Saathi") | ||
|
||
# Generate empty lists for bot_response and user_input. | ||
## bot_response stores AI generated responses | ||
if 'bot_response' not in st.session_state: | ||
st.session_state['bot_response'] = ["I'm Saathi, How may I help you?"] | ||
## user_input stores User's questions | ||
if 'user_input' not in st.session_state: | ||
st.session_state['user_input'] = ['Hi!'] | ||
|
||
# Layout of input/response containers | ||
input_container = st.container() | ||
colored_header(label='', description='', color_name='blue-30') | ||
response_container = st.container() | ||
|
||
# User input | ||
## Function for taking user provided prompt as input | ||
def get_input(): | ||
input_text = st.text_input("You: ", "", key="input") | ||
return input_text | ||
## Applying the user input box | ||
with input_container: | ||
user_input = get_input() | ||
|
||
# Response output | ||
## Function for taking user prompt as input followed by producing AI generated responses | ||
def generate_response(prompt): | ||
chatbot = hugchat.ChatBot(cookie_path="cookies.json") | ||
response = chatbot.chat(prompt) | ||
return response | ||
|
||
## Conditional display of AI generated responses as a function of user provided prompts | ||
with response_container: | ||
if user_input: | ||
response = generate_response(user_input) | ||
st.session_state.user_input.append(user_input) | ||
st.session_state.bot_response.append(response) | ||
|
||
if st.session_state['bot_response']: | ||
for i in range(len(st.session_state['bot_response'])): | ||
message(st.session_state['user_input'][i], is_user=True, key=str(i) + '_user') | ||
message(st.session_state['bot_response'][i], key=str(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters