Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,33 +101,11 @@ def page1():
|
|
| 101 |
metadata={'session_id': st.session_state.session_id}
|
| 102 |
)
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
| 106 |
-
# Retrieve the list of messages
|
| 107 |
-
st.session_state.messages = client.beta.threads.messages.list(
|
| 108 |
-
thread_id=st.session_state.thread.id
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
end_time = time.time() # Stop the timer
|
| 112 |
-
duration = end_time - start_time # Calculate duration
|
| 113 |
-
st.write(f"Response time: {duration:.2f} seconds")
|
| 114 |
-
|
| 115 |
-
# Display messages
|
| 116 |
-
for message in reversed(st.session_state.messages.data):
|
| 117 |
-
if message.role in ["user", "assistant"]:
|
| 118 |
-
with st.chat_message(message.role):
|
| 119 |
-
for content_part in message.content:
|
| 120 |
-
if content_part.type == 'text': # For text responses
|
| 121 |
-
message_text = content_part.text.value
|
| 122 |
-
st.markdown(message_text)
|
| 123 |
-
elif hasattr(content_part, 'image_file') and content_part.image_file:
|
| 124 |
-
image = handle_and_display_image(content_part.image_file.file_id)
|
| 125 |
-
if image:
|
| 126 |
-
st.image(image, caption="Generated Image")
|
| 127 |
-
|
| 128 |
-
start_time = time.time() # Start the timer
|
| 129 |
|
| 130 |
if prompt := st.chat_input("Wie kann ich dir helfen?"):
|
|
|
|
| 131 |
with st.chat_message('user'):
|
| 132 |
st.write(prompt)
|
| 133 |
|
|
@@ -168,18 +146,29 @@ def page1():
|
|
| 168 |
else:
|
| 169 |
st.error("FAILED: The OpenAI API is currently processing too many requests. Please try again later ......")
|
| 170 |
|
| 171 |
-
#
|
| 172 |
-
elif st.session_state.run.status
|
| 173 |
-
#
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
)
|
| 178 |
-
if st.session_state.retry_error < 3:
|
| 179 |
-
time.sleep(3)
|
| 180 |
-
st.rerun()
|
| 181 |
-
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
|
| 185 |
|
|
|
|
| 101 |
metadata={'session_id': st.session_state.session_id}
|
| 102 |
)
|
| 103 |
|
| 104 |
+
# Initialize start_time to None
|
| 105 |
+
start_time = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
if prompt := st.chat_input("Wie kann ich dir helfen?"):
|
| 108 |
+
start_time = time.time() # Start the timer when the user submits a query
|
| 109 |
with st.chat_message('user'):
|
| 110 |
st.write(prompt)
|
| 111 |
|
|
|
|
| 146 |
else:
|
| 147 |
st.error("FAILED: The OpenAI API is currently processing too many requests. Please try again later ......")
|
| 148 |
|
| 149 |
+
# When the run is completed
|
| 150 |
+
elif hasattr(st.session_state.run, 'status') and st.session_state.run.status == "completed":
|
| 151 |
+
end_time = time.time() # Stop the timer when the response is received
|
| 152 |
+
if start_time:
|
| 153 |
+
duration = end_time - start_time # Calculate duration
|
| 154 |
+
st.write(f"Response time: {duration:.2f} seconds")
|
| 155 |
+
|
| 156 |
+
# Retrieve the list of messages and display them
|
| 157 |
+
st.session_state.messages = client.beta.threads.messages.list(
|
| 158 |
+
thread_id=st.session_state.thread.id
|
| 159 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
for message in reversed(st.session_state.messages.data):
|
| 162 |
+
if message.role in ["user", "assistant"]:
|
| 163 |
+
with st.chat_message(message.role):
|
| 164 |
+
for content_part in message.content:
|
| 165 |
+
if content_part.type == 'text': # For text responses
|
| 166 |
+
message_text = content_part.text.value
|
| 167 |
+
st.markdown(message_text)
|
| 168 |
+
elif hasattr(content_part, 'image_file') and content_part.image_file:
|
| 169 |
+
image = handle_and_display_image(content_part.image_file.file_id)
|
| 170 |
+
if image:
|
| 171 |
+
st.image(image, caption="Generated Image")
|
| 172 |
|
| 173 |
|
| 174 |
|