kaleidoskop-hug
commited on
Commit
•
a42067e
1
Parent(s):
b713846
Update app.py
Browse files
app.py
CHANGED
@@ -73,21 +73,12 @@ if "prev_option" not in st.session_state:
|
|
73 |
# st.session_state.prev_option = selected_model
|
74 |
# reset_conversation()
|
75 |
|
76 |
-
#Pull in the model we want to use
|
77 |
-
#repo_id = model_links[selected_model]
|
78 |
-
|
79 |
st.subheader(f'{selected_model}')
|
80 |
|
81 |
-
# Set a default model
|
82 |
-
#if selected_model not in st.session_state:
|
83 |
-
# st.session_state[selected_model] = model_links[selected_model]
|
84 |
-
|
85 |
# Initialize chat history
|
86 |
if "messages" not in st.session_state:
|
87 |
st.session_state.messages = []
|
88 |
|
89 |
-
def remove_message(position):
|
90 |
-
st.toast("remove message no:" + position)
|
91 |
|
92 |
# Display chat messages from history on app rerun
|
93 |
pos = 0
|
@@ -96,7 +87,11 @@ for message in st.session_state.messages:
|
|
96 |
with st.chat_message(message["role"]):
|
97 |
col1, col2 = st.columns([9,1])
|
98 |
col1.markdown(message["content"])
|
99 |
-
col2.button("remove", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
|
|
|
|
|
|
|
|
100 |
|
101 |
|
102 |
if "remove" not in st.session_state:
|
@@ -117,18 +112,26 @@ if st.session_state.remove:
|
|
117 |
# Accept user input
|
118 |
if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
|
119 |
# Display user message in chat message container and Add user message to chat history
|
|
|
120 |
with st.chat_message("user"):
|
121 |
-
st.
|
|
|
|
|
122 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
123 |
|
124 |
# Display assistant response in chat message container
|
125 |
assistant = ask_assistant_stream(model_links[selected_model], st.session_state.messages, temp_values, max_token_value)
|
|
|
126 |
if "stream" in assistant:
|
127 |
with st.chat_message("assistant"):
|
128 |
-
|
|
|
|
|
129 |
else:
|
130 |
with st.chat_message("assistant"):
|
131 |
-
|
|
|
|
|
132 |
|
133 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
134 |
|
|
|
73 |
# st.session_state.prev_option = selected_model
|
74 |
# reset_conversation()
|
75 |
|
|
|
|
|
|
|
76 |
st.subheader(f'{selected_model}')
|
77 |
|
|
|
|
|
|
|
|
|
78 |
# Initialize chat history
|
79 |
if "messages" not in st.session_state:
|
80 |
st.session_state.messages = []
|
81 |
|
|
|
|
|
82 |
|
83 |
# Display chat messages from history on app rerun
|
84 |
pos = 0
|
|
|
87 |
with st.chat_message(message["role"]):
|
88 |
col1, col2 = st.columns([9,1])
|
89 |
col1.markdown(message["content"])
|
90 |
+
col2.button("remove-"+str(pos), key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
91 |
+
|
92 |
+
|
93 |
+
def remove_message(position):
|
94 |
+
st.toast("remove message no:" + position)
|
95 |
|
96 |
|
97 |
if "remove" not in st.session_state:
|
|
|
112 |
# Accept user input
|
113 |
if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
|
114 |
# Display user message in chat message container and Add user message to chat history
|
115 |
+
pos = st.session_state.messages.length
|
116 |
with st.chat_message("user"):
|
117 |
+
col1, col2 = st.columns([9,1])
|
118 |
+
col1.markdown(prompt)
|
119 |
+
col2.button("remove-"+str(pos), key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
120 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
121 |
|
122 |
# Display assistant response in chat message container
|
123 |
assistant = ask_assistant_stream(model_links[selected_model], st.session_state.messages, temp_values, max_token_value)
|
124 |
+
pos = st.session_state.messages.length
|
125 |
if "stream" in assistant:
|
126 |
with st.chat_message("assistant"):
|
127 |
+
col1, col2 = st.columns([9,1])
|
128 |
+
response = col1.write_stream(assistant["stream"])
|
129 |
+
col2.button("remove-"+str(pos), key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
130 |
else:
|
131 |
with st.chat_message("assistant"):
|
132 |
+
col1, col2 = st.columns([9,1])
|
133 |
+
response = col1.write("Failure!")
|
134 |
+
col2.button("remove-"+str(pos), key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
135 |
|
136 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
137 |
|