Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -176,59 +176,6 @@ def page1():
|
|
| 176 |
st.image(image, caption="Generated Image")
|
| 177 |
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
prompt = st.text_input("Wie kann ich dir helfen?")
|
| 182 |
-
if st.button("Submit"):
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
# Add message to the thread
|
| 186 |
-
st.session_state.messages = client.beta.threads.messages.create(
|
| 187 |
-
thread_id=st.session_state.thread.id,
|
| 188 |
-
role="user",
|
| 189 |
-
content=prompt
|
| 190 |
-
)
|
| 191 |
-
|
| 192 |
-
# Do a run to process the messages in the thread
|
| 193 |
-
st.session_state.run = client.beta.threads.runs.create(
|
| 194 |
-
thread_id=st.session_state.thread.id,
|
| 195 |
-
assistant_id=st.session_state.assistant.id,
|
| 196 |
-
)
|
| 197 |
-
if st.session_state.retry_error < 3:
|
| 198 |
-
time.sleep(1) # Wait 1 second before checking run status
|
| 199 |
-
st.rerun()
|
| 200 |
-
|
| 201 |
-
# Check if 'run' object has 'status' attribute
|
| 202 |
-
if hasattr(st.session_state.run, 'status'):
|
| 203 |
-
# Handle the 'running' status
|
| 204 |
-
if st.session_state.run.status == "running":
|
| 205 |
-
with st.chat_message('assistant'):
|
| 206 |
-
st.write("Thinking ......")
|
| 207 |
-
if st.session_state.retry_error < 3:
|
| 208 |
-
time.sleep(1) # Short delay to prevent immediate rerun
|
| 209 |
-
st.rerun()
|
| 210 |
-
|
| 211 |
-
# Handle the 'failed' status
|
| 212 |
-
elif st.session_state.run.status == "failed":
|
| 213 |
-
st.session_state.retry_error += 1
|
| 214 |
-
with st.chat_message('assistant'):
|
| 215 |
-
if st.session_state.retry_error < 3:
|
| 216 |
-
st.write("Run failed, retrying ......")
|
| 217 |
-
time.sleep(3) # Longer delay before retrying
|
| 218 |
-
st.rerun()
|
| 219 |
-
else:
|
| 220 |
-
st.error("FAILED: The OpenAI API is currently processing too many requests. Please try again later ......")
|
| 221 |
-
|
| 222 |
-
# Handle any status that is not 'completed'
|
| 223 |
-
elif st.session_state.run.status != "completed":
|
| 224 |
-
# Attempt to retrieve the run again
|
| 225 |
-
st.session_state.run = client.beta.threads.runs.retrieve(
|
| 226 |
-
thread_id=st.session_state.thread.id,
|
| 227 |
-
run_id=st.session_state.run.id,
|
| 228 |
-
)
|
| 229 |
-
if st.session_state.retry_error < 3:
|
| 230 |
-
time.sleep(3)
|
| 231 |
-
st.rerun()
|
| 232 |
|
| 233 |
if __name__ == "__main__":
|
| 234 |
main()
|
|
|
|
| 176 |
st.image(image, caption="Generated Image")
|
| 177 |
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
if __name__ == "__main__":
|
| 181 |
main()
|