Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import cohere
|
| 3 |
import os
|
| 4 |
-
import time
|
| 5 |
|
| 6 |
st.set_page_config(page_title="Cohere Chat", layout="wide")
|
| 7 |
|
|
@@ -118,39 +117,18 @@ if prompt := st.chat_input("Message..."):
|
|
| 118 |
try:
|
| 119 |
co = cohere.ClientV2(api_key)
|
| 120 |
with st.chat_message("assistant", avatar=AI_PFP):
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
progress_bar = st.progress(0)
|
| 124 |
-
|
| 125 |
-
full_response = ""
|
| 126 |
-
chunk_count = 0
|
| 127 |
-
max_chunks = 20
|
| 128 |
-
|
| 129 |
-
for event in co.chat_stream(
|
| 130 |
model=selected_model,
|
| 131 |
messages=st.session_state.messages
|
| 132 |
-
)
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
chunk_count += 1
|
| 142 |
-
progress_value = min(chunk_count / max_chunks, 0.95)
|
| 143 |
-
progress_bar.progress(progress_value)
|
| 144 |
-
|
| 145 |
-
progress_bar.progress(1.0)
|
| 146 |
-
message_placeholder.markdown(full_response)
|
| 147 |
-
|
| 148 |
-
time.sleep(0.5)
|
| 149 |
-
|
| 150 |
-
progress_bar.empty()
|
| 151 |
-
|
| 152 |
-
reply = full_response
|
| 153 |
-
|
| 154 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 155 |
|
| 156 |
except Exception as e:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import cohere
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Cohere Chat", layout="wide")
|
| 6 |
|
|
|
|
| 117 |
try:
|
| 118 |
co = cohere.ClientV2(api_key)
|
| 119 |
with st.chat_message("assistant", avatar=AI_PFP):
|
| 120 |
+
response = co.chat(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
model=selected_model,
|
| 122 |
messages=st.session_state.messages
|
| 123 |
+
)
|
| 124 |
+
if hasattr(response, "message") and hasattr(response.message, "content"):
|
| 125 |
+
content_items = response.message.content
|
| 126 |
+
reply = "".join(getattr(item, 'text', '') for item in content_items)
|
| 127 |
+
else:
|
| 128 |
+
st.write(response)
|
| 129 |
+
reply = "❗️Couldn't extract reply from the Cohere response."
|
| 130 |
+
st.markdown(reply)
|
| 131 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 133 |
|
| 134 |
except Exception as e:
|