kaleidoskop-hug
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -40,11 +40,9 @@ def ask_assistant_stream(st_model, st_messages, st_temp_value, st_max_tokens):
|
|
40 |
stream=True,
|
41 |
max_tokens=st_max_tokens,
|
42 |
)
|
43 |
-
st.write("success")
|
44 |
response["stream"] = stream
|
45 |
|
46 |
except Exception as e:
|
47 |
-
st.write("exception")
|
48 |
pass
|
49 |
|
50 |
return response
|
@@ -64,30 +62,24 @@ max_token_value = st.sidebar.slider('Select a max_token value', 1000, 9000, (500
|
|
64 |
#Add reset button to clear conversation
|
65 |
st.sidebar.button('Reset Chat', on_click=reset_conversation) #Reset button
|
66 |
|
67 |
-
|
68 |
# Create model description
|
69 |
st.sidebar.write(f"You're now chatting with **{selected_model}**")
|
70 |
st.sidebar.markdown("*Generated content may be inaccurate or false.*")
|
71 |
-
# st.sidebar.markdown("\n[TypeGPT](https://typegpt.net).")
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
|
76 |
if "prev_option" not in st.session_state:
|
77 |
st.session_state.prev_option = selected_model
|
78 |
|
|
|
79 |
if st.session_state.prev_option != selected_model:
|
80 |
st.session_state.messages = []
|
81 |
# st.write(f"Changed to {selected_model}")
|
82 |
st.session_state.prev_option = selected_model
|
83 |
reset_conversation()
|
84 |
-
|
85 |
-
|
86 |
|
87 |
#Pull in the model we want to use
|
88 |
repo_id = model_links[selected_model]
|
89 |
|
90 |
-
|
91 |
st.subheader(f'{selected_model}')
|
92 |
# # st.title(f'ChatBot Using {selected_model}')
|
93 |
|
@@ -99,7 +91,6 @@ if selected_model not in st.session_state:
|
|
99 |
if "messages" not in st.session_state:
|
100 |
st.session_state.messages = []
|
101 |
|
102 |
-
|
103 |
# Display chat messages from history on app rerun
|
104 |
for message in st.session_state.messages:
|
105 |
with st.chat_message(message["role"]):
|
@@ -108,9 +99,8 @@ for message in st.session_state.messages:
|
|
108 |
if "retry" not in st.session_state:
|
109 |
st.session_state.retry= False
|
110 |
|
111 |
-
def retry_click():
|
112 |
-
st.session_state.retry= True
|
113 |
-
|
114 |
|
115 |
if st.session_state.retry:
|
116 |
lastmessage = st.session_state.messages.pop()
|
@@ -123,8 +113,8 @@ if st.session_state.retry:
|
|
123 |
if "remove" not in st.session_state:
|
124 |
st.session_state.remove= False
|
125 |
|
126 |
-
def remove_click():
|
127 |
-
st.session_state.remove= True
|
128 |
|
129 |
if st.session_state.remove:
|
130 |
lastmessage = st.session_state.messages.pop()
|
@@ -155,5 +145,9 @@ if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
|
|
155 |
|
156 |
if len(st.session_state.messages)>0:
|
157 |
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
158 |
col1.button("retry", key="retryButton", on_click=retry_click)
|
159 |
col2.button("remove", key="removeButton", on_click=remove_click)
|
|
|
|
40 |
stream=True,
|
41 |
max_tokens=st_max_tokens,
|
42 |
)
|
|
|
43 |
response["stream"] = stream
|
44 |
|
45 |
except Exception as e:
|
|
|
46 |
pass
|
47 |
|
48 |
return response
|
|
|
62 |
#Add reset button to clear conversation
|
63 |
st.sidebar.button('Reset Chat', on_click=reset_conversation) #Reset button
|
64 |
|
|
|
65 |
# Create model description
|
66 |
st.sidebar.write(f"You're now chatting with **{selected_model}**")
|
67 |
st.sidebar.markdown("*Generated content may be inaccurate or false.*")
|
|
|
|
|
|
|
|
|
68 |
|
69 |
if "prev_option" not in st.session_state:
|
70 |
st.session_state.prev_option = selected_model
|
71 |
|
72 |
+
'''
|
73 |
if st.session_state.prev_option != selected_model:
|
74 |
st.session_state.messages = []
|
75 |
# st.write(f"Changed to {selected_model}")
|
76 |
st.session_state.prev_option = selected_model
|
77 |
reset_conversation()
|
78 |
+
'''
|
|
|
79 |
|
80 |
#Pull in the model we want to use
|
81 |
repo_id = model_links[selected_model]
|
82 |
|
|
|
83 |
st.subheader(f'{selected_model}')
|
84 |
# # st.title(f'ChatBot Using {selected_model}')
|
85 |
|
|
|
91 |
if "messages" not in st.session_state:
|
92 |
st.session_state.messages = []
|
93 |
|
|
|
94 |
# Display chat messages from history on app rerun
|
95 |
for message in st.session_state.messages:
|
96 |
with st.chat_message(message["role"]):
|
|
|
99 |
if "retry" not in st.session_state:
|
100 |
st.session_state.retry= False
|
101 |
|
102 |
+
#def retry_click():
|
103 |
+
# st.session_state.retry= True
|
|
|
104 |
|
105 |
if st.session_state.retry:
|
106 |
lastmessage = st.session_state.messages.pop()
|
|
|
113 |
if "remove" not in st.session_state:
|
114 |
st.session_state.remove= False
|
115 |
|
116 |
+
#def remove_click():
|
117 |
+
# st.session_state.remove= True
|
118 |
|
119 |
if st.session_state.remove:
|
120 |
lastmessage = st.session_state.messages.pop()
|
|
|
145 |
|
146 |
if len(st.session_state.messages)>0:
|
147 |
col1, col2 = st.columns(2)
|
148 |
+
col1.button("retry", key="retry")
|
149 |
+
col2.button("remove", key="remove")
|
150 |
+
'''
|
151 |
col1.button("retry", key="retryButton", on_click=retry_click)
|
152 |
col2.button("remove", key="removeButton", on_click=remove_click)
|
153 |
+
'''
|