Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from streamlit_chat import message
|
| 3 |
from streamlit_extras.colored_header import colored_header
|
| 4 |
from streamlit_extras.add_vertical_space import add_vertical_space
|
| 5 |
from hugchat import hugchat
|
|
|
|
| 6 |
|
| 7 |
st.set_page_config(page_title="HugChat - An LLM-powered Streamlit app")
|
| 8 |
|
| 9 |
# Sidebar contents
|
| 10 |
with st.sidebar:
|
| 11 |
st.title('🤗💬 HugChat App')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
st.markdown('''
|
| 13 |
## About
|
| 14 |
This app is an LLM-powered chatbot built using:
|
| 15 |
- [Streamlit](https://streamlit.io/)
|
| 16 |
- [HugChat](https://github.com/Soulter/hugging-chat-api)
|
| 17 |
- [OpenAssistant/oasst-sft-6-llama-30b-xor](https://huggingface.co/OpenAssistant/oasst-sft-6-llama-30b-xor) LLM model
|
| 18 |
-
|
| 19 |
-
💡 Note: No API key required!
|
| 20 |
''')
|
| 21 |
add_vertical_space(5)
|
| 22 |
st.write('Made with ❤️ by [Data Professor](https://youtube.com/dataprofessor)')
|
|
@@ -45,19 +51,24 @@ with input_container:
|
|
| 45 |
|
| 46 |
# Response output
|
| 47 |
## Function for taking user prompt as input followed by producing AI generated responses
|
| 48 |
-
def generate_response(prompt):
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
response = chatbot.chat(prompt)
|
| 51 |
return response
|
| 52 |
|
| 53 |
## Conditional display of AI generated responses as a function of user provided prompts
|
| 54 |
with response_container:
|
| 55 |
-
if user_input:
|
| 56 |
-
response = generate_response(user_input)
|
| 57 |
st.session_state.past.append(user_input)
|
| 58 |
st.session_state.generated.append(response)
|
| 59 |
|
| 60 |
if st.session_state['generated']:
|
| 61 |
for i in range(len(st.session_state['generated'])):
|
| 62 |
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
| 63 |
-
message(st.session_state["generated"][i], key=str(i))
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
from streamlit_chat import message
|
| 4 |
from streamlit_extras.colored_header import colored_header
|
| 5 |
from streamlit_extras.add_vertical_space import add_vertical_space
|
| 6 |
from hugchat import hugchat
|
| 7 |
+
from hugchat.login import Login
|
| 8 |
|
| 9 |
st.set_page_config(page_title="HugChat - An LLM-powered Streamlit app")
|
| 10 |
|
| 11 |
# Sidebar contents
|
| 12 |
with st.sidebar:
|
| 13 |
st.title('🤗💬 HugChat App')
|
| 14 |
+
|
| 15 |
+
st.header('Hugging Face Login')
|
| 16 |
+
hf_email = st.text_input('Enter E-mail:', type='password')
|
| 17 |
+
hf_pass = st.text_input('Enter password:', type='password')
|
| 18 |
+
|
| 19 |
st.markdown('''
|
| 20 |
## About
|
| 21 |
This app is an LLM-powered chatbot built using:
|
| 22 |
- [Streamlit](https://streamlit.io/)
|
| 23 |
- [HugChat](https://github.com/Soulter/hugging-chat-api)
|
| 24 |
- [OpenAssistant/oasst-sft-6-llama-30b-xor](https://huggingface.co/OpenAssistant/oasst-sft-6-llama-30b-xor) LLM model
|
| 25 |
+
|
|
|
|
| 26 |
''')
|
| 27 |
add_vertical_space(5)
|
| 28 |
st.write('Made with ❤️ by [Data Professor](https://youtube.com/dataprofessor)')
|
|
|
|
| 51 |
|
| 52 |
# Response output
|
| 53 |
## Function for taking user prompt as input followed by producing AI generated responses
|
| 54 |
+
def generate_response(prompt, email, passwd):
|
| 55 |
+
# Hugging Face Login
|
| 56 |
+
sign = Login(email, passwd)
|
| 57 |
+
cookies = sign.login()
|
| 58 |
+
sign.saveCookies()
|
| 59 |
+
# Create ChatBot
|
| 60 |
+
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
|
| 61 |
response = chatbot.chat(prompt)
|
| 62 |
return response
|
| 63 |
|
| 64 |
## Conditional display of AI generated responses as a function of user provided prompts
|
| 65 |
with response_container:
|
| 66 |
+
if user_input and hf_email and hf_pass:
|
| 67 |
+
response = generate_response(user_input, hf_email, hf_pass)
|
| 68 |
st.session_state.past.append(user_input)
|
| 69 |
st.session_state.generated.append(response)
|
| 70 |
|
| 71 |
if st.session_state['generated']:
|
| 72 |
for i in range(len(st.session_state['generated'])):
|
| 73 |
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
| 74 |
+
message(st.session_state["generated"][i], key=str(i))
|