ogegadavis254
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
-
import json
|
4 |
import os
|
5 |
from dotenv import load_dotenv
|
6 |
|
@@ -10,33 +9,13 @@ def reset_conversation():
|
|
10 |
'''
|
11 |
Resets Conversation
|
12 |
'''
|
13 |
-
st.session_state.conversation = []
|
14 |
st.session_state.messages = []
|
15 |
return None
|
16 |
|
17 |
-
# Define model
|
18 |
-
|
19 |
-
"Addiction recovery AI": "NousResearch/Nous-Hermes-2-Yi-34B",
|
20 |
-
"Mental health AI": "NousResearch/Nous-Hermes-2-Yi-34B"
|
21 |
-
}
|
22 |
-
|
23 |
-
model_info = {
|
24 |
-
"Addiction recovery AI": {
|
25 |
-
'description': "This model provides support and guidance for individuals on their addiction recovery journey.",
|
26 |
-
'logo': 'https://example.com/addiction_recovery_logo.png'
|
27 |
-
},
|
28 |
-
"Mental health AI": {
|
29 |
-
'description': "This model offers assistance and resources for individuals dealing with mental health concerns.",
|
30 |
-
'logo': 'https://example.com/mental_health_logo.png'
|
31 |
-
}
|
32 |
-
}
|
33 |
-
|
34 |
-
# Function to interact with Hugging Face models
|
35 |
-
def interact_with_huggingface_model(messages, model):
|
36 |
-
# Add your code here to interact with the Hugging Face model
|
37 |
-
pass
|
38 |
|
39 |
-
# Function to interact with the Together API
|
40 |
def interact_with_together_api(messages):
|
41 |
all_messages = []
|
42 |
|
@@ -52,7 +31,7 @@ def interact_with_together_api(messages):
|
|
52 |
|
53 |
url = "https://api.together.xyz/v1/chat/completions"
|
54 |
payload = {
|
55 |
-
"model":
|
56 |
"temperature": 1.05,
|
57 |
"top_p": 0.9,
|
58 |
"top_k": 50,
|
@@ -77,18 +56,9 @@ def interact_with_together_api(messages):
|
|
77 |
|
78 |
return assistant_response
|
79 |
|
80 |
-
# Create sidebar with
|
81 |
-
selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
|
82 |
st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
83 |
|
84 |
-
# Display model description and logo
|
85 |
-
st.sidebar.write(f"You're now chatting with **{selected_model}**")
|
86 |
-
st.sidebar.markdown(model_info[selected_model]['description'])
|
87 |
-
st.sidebar.image(model_info[selected_model]['logo'])
|
88 |
-
st.sidebar.markdown("*Generated content may be inaccurate or false.*")
|
89 |
-
st.sidebar.markdown("\nLearn how to build this chatbot [here](https://ngebodh.github.io/projects/2024-03-05/).")
|
90 |
-
st.sidebar.markdown("\nRun into issues? Try the [back-up](https://huggingface.co/spaces/ngebodh/SimpleChatbot-Backup).")
|
91 |
-
|
92 |
# Initialize chat history
|
93 |
if "messages" not in st.session_state:
|
94 |
st.session_state.messages = []
|
@@ -99,18 +69,15 @@ for message in st.session_state.messages:
|
|
99 |
st.markdown(message[1])
|
100 |
|
101 |
# Accept user input
|
102 |
-
if prompt := st.chat_input(
|
103 |
# Display user message in chat message container
|
104 |
with st.chat_message("user"):
|
105 |
st.markdown(prompt)
|
106 |
# Add user message to chat history
|
107 |
st.session_state.messages.append(("user", prompt))
|
108 |
|
109 |
-
# Interact with
|
110 |
-
|
111 |
-
assistant_response = interact_with_together_api(st.session_state.messages)
|
112 |
-
else:
|
113 |
-
assistant_response = interact_with_huggingface_model(st.session_state.messages, model_links[selected_model])
|
114 |
|
115 |
# Display assistant response in chat message container
|
116 |
with st.empty():
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
|
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
|
|
|
9 |
'''
|
10 |
Resets Conversation
|
11 |
'''
|
|
|
12 |
st.session_state.messages = []
|
13 |
return None
|
14 |
|
15 |
+
# Define model link for the Nous model
|
16 |
+
model_link = "NousResearch/Nous-Hermes-2-Yi-34B"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Function to interact with the Nous model via the Together API
|
19 |
def interact_with_together_api(messages):
|
20 |
all_messages = []
|
21 |
|
|
|
31 |
|
32 |
url = "https://api.together.xyz/v1/chat/completions"
|
33 |
payload = {
|
34 |
+
"model": model_link,
|
35 |
"temperature": 1.05,
|
36 |
"top_p": 0.9,
|
37 |
"top_k": 50,
|
|
|
56 |
|
57 |
return assistant_response
|
58 |
|
59 |
+
# Create sidebar with reset button
|
|
|
60 |
st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# Initialize chat history
|
63 |
if "messages" not in st.session_state:
|
64 |
st.session_state.messages = []
|
|
|
69 |
st.markdown(message[1])
|
70 |
|
71 |
# Accept user input
|
72 |
+
if prompt := st.chat_input("Hi, I'm the Nous model, ask me a question"):
|
73 |
# Display user message in chat message container
|
74 |
with st.chat_message("user"):
|
75 |
st.markdown(prompt)
|
76 |
# Add user message to chat history
|
77 |
st.session_state.messages.append(("user", prompt))
|
78 |
|
79 |
+
# Interact with the Nous model
|
80 |
+
assistant_response = interact_with_together_api(st.session_state.messages)
|
|
|
|
|
|
|
81 |
|
82 |
# Display assistant response in chat message container
|
83 |
with st.empty():
|