Spaces:
Runtime error
Runtime error
Alex commited on
Commit ·
5b6689e
1
Parent(s): 8270617
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,17 @@ 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')
|
|
@@ -13,7 +21,7 @@ with st.sidebar:
|
|
| 13 |
## About
|
| 14 |
This app is an LLM-powered chatbot built using:
|
| 15 |
- [Streamlit](https://streamlit.io/)
|
| 16 |
-
- [OpenAssistant/oasst-sft-6-llama-30b-xor]
|
| 17 |
|
| 18 |
💡 Note: No API key required!
|
| 19 |
''')
|
|
@@ -45,7 +53,8 @@ with input_container:
|
|
| 45 |
# Response output
|
| 46 |
## Function for taking user prompt as input followed by producing AI generated responses
|
| 47 |
def generate_response(prompt):
|
| 48 |
-
chatbot = hugchat.ChatBot()
|
|
|
|
| 49 |
response = chatbot.chat(prompt)
|
| 50 |
return response
|
| 51 |
|
|
@@ -59,4 +68,8 @@ with response_container:
|
|
| 59 |
if st.session_state['generated']:
|
| 60 |
for i in range(len(st.session_state['generated'])):
|
| 61 |
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
| 62 |
-
message(st.session_state["generated"][i], key=str(i))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
from transformers import AutoModelForCausalLM
|
| 7 |
|
| 8 |
st.set_page_config(page_title="HugChat - An LLM-powered Streamlit app")
|
| 9 |
|
| 10 |
+
def check_model(model_name):
|
| 11 |
+
try:
|
| 12 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 13 |
+
st.write(f"Model {model_name} loaded successfully.")
|
| 14 |
+
except Exception as e:
|
| 15 |
+
st.write(f"Failed to load model {model_name}. Error: {str(e)}")
|
| 16 |
+
|
| 17 |
# Sidebar contents
|
| 18 |
with st.sidebar:
|
| 19 |
st.title('🤗💬 HugChat App')
|
|
|
|
| 21 |
## About
|
| 22 |
This app is an LLM-powered chatbot built using:
|
| 23 |
- [Streamlit](https://streamlit.io/)
|
| 24 |
+
- [OpenAssistant/oasst-sft-6-llama-30b-xor] LLM model
|
| 25 |
|
| 26 |
💡 Note: No API key required!
|
| 27 |
''')
|
|
|
|
| 53 |
# Response output
|
| 54 |
## Function for taking user prompt as input followed by producing AI generated responses
|
| 55 |
def generate_response(prompt):
|
| 56 |
+
chatbot = hugchat.ChatBot(model_name="gpt3") # For GPT-3
|
| 57 |
+
# chatbot = hugchat.ChatBot(model_name="gpt4") # For GPT-4
|
| 58 |
response = chatbot.chat(prompt)
|
| 59 |
return response
|
| 60 |
|
|
|
|
| 68 |
if st.session_state['generated']:
|
| 69 |
for i in range(len(st.session_state['generated'])):
|
| 70 |
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
| 71 |
+
message(st.session_state["generated"][i], key=str(i))
|
| 72 |
+
|
| 73 |
+
# Check the model
|
| 74 |
+
check_model("gpt3") # For GPT-3
|
| 75 |
+
# check_model("gpt4") # For GPT-4
|