Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import cohere
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Cohere Chat", layout="wide")
|
| 6 |
|
|
@@ -118,7 +119,12 @@ if prompt := st.chat_input("Message..."):
|
|
| 118 |
co = cohere.ClientV2(api_key)
|
| 119 |
with st.chat_message("assistant", avatar=AI_PFP):
|
| 120 |
message_placeholder = st.empty()
|
|
|
|
|
|
|
|
|
|
| 121 |
full_response = ""
|
|
|
|
|
|
|
| 122 |
|
| 123 |
for event in co.chat_stream(
|
| 124 |
model=selected_model,
|
|
@@ -131,8 +137,18 @@ if prompt := st.chat_input("Message..."):
|
|
| 131 |
delta_text = getattr(content_item, "text", "")
|
| 132 |
full_response += delta_text
|
| 133 |
message_placeholder.markdown(full_response + "▌")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
|
|
|
| 135 |
message_placeholder.markdown(full_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
reply = full_response
|
| 137 |
|
| 138 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
|
|
|
| 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 |
|
|
|
|
| 119 |
co = cohere.ClientV2(api_key)
|
| 120 |
with st.chat_message("assistant", avatar=AI_PFP):
|
| 121 |
message_placeholder = st.empty()
|
| 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,
|
|
|
|
| 137 |
delta_text = getattr(content_item, "text", "")
|
| 138 |
full_response += delta_text
|
| 139 |
message_placeholder.markdown(full_response + "▌")
|
| 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})
|