Skip to content

Commit

Permalink
updated app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Gopps95 committed Mar 19, 2024
1 parent b8e041d commit 76bca5c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions app.py
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))
4 changes: 2 additions & 2 deletions cookies.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"domain": ".huggingface.co",
"expirationDate": 1711213172,
"expirationDate": 1711213743,
"hostOnly": false,
"httpOnly": false,
"name": "aws-waf-token",
Expand All @@ -36,7 +36,7 @@
"secure": true,
"session": false,
"storeId": null,
"value": "9be95b9e-e962-489f-b09a-6862c0b9127e:BgoAY5R24aoDAAAA:36VEwq5606i6+1phfoqS9GA/U4IZEQkufuuYxrUK53zORbEzJEkX81XIM5XlycVgFTmz+NxeP5dRdZ7qxY2uLg+e975hP+7YumF3X1apAjXXuit4y9xHl0jxEuVZe6oMHuerGY8ZKtC160gdXrWqGMxbvSvpxG+EjpevfFrlwx2k9Tkd9fDnARdTZ9SnFcyet4CCz+zB7DqYoh5HAwUbaDUs2lwY2eB7VkQaovPfMVaYZSssOmRKf4mgyU9QRp95PrhyCwmLaZE1KQzNLJA="
"value": "59b87e0b-b6dc-4a32-bce8-64a37f0ca560:HgoAquN3R+wDAAAA:mObzyLXw7TYRpPj37JHUAgzhDb23rtcqjLj6pn+CpmN39Rf7xhblox6LibFo/wxS/rGKOZ1b+Blf63hzo3Omm9APF9LlDg71K8NpPJs04afLBVeXPoKm2obgGJfbJnls58kVQ0t0L7C1LW8TMSwJ9ODAachDUYa0Z3Z93uagzUiHgW3+IfEEktdbEvBBsNRmQQP++O+RZKw0Fn0+HCE6AbTY3TrPABigIV1F/dtYjJJa9tHIHXT2Igj6OJDrt6B2CT6WHPaIVcWMICIKons="
},
{
"domain": ".huggingface.co",
Expand Down

0 comments on commit 76bca5c

Please sign in to comment.