Fernando Knüttel commited on
Commit
e7571d3
·
1 Parent(s): 2ab137c

better user_experience through changing loading screen text for model requests to the backend

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +27 -15
src/streamlit_app.py CHANGED
@@ -99,7 +99,7 @@ if check_password():
99
  justify-content: center;
100
  align-items: center;
101
  z-index: 9999;
102
- animation: fadeout 2s ease 3s forwards;
103
  }
104
 
105
  /* Text & Animation */
@@ -130,7 +130,7 @@ if check_password():
130
  st.markdown(splash_html, unsafe_allow_html=True)
131
  if requests.get(API_URL + "/model_status").json()['status'] != "ready":
132
  requests.post(API_URL + "/load_model")
133
- time.sleep(20)
134
  st.session_state.splash_done = True
135
  st.rerun()
136
  else:
@@ -145,6 +145,9 @@ if check_password():
145
 
146
  if "fallback_counter" not in st.session_state:
147
  st.session_state.fallback_counter = 0
 
 
 
148
 
149
  st.markdown("""
150
  <style>
@@ -232,6 +235,7 @@ if check_password():
232
 
233
  with st.chat_message("assistant", avatar=avatar_path):
234
  messages = [
 
235
  "🔄 Initializing application…",
236
  "📚 Loading memory…",
237
  "🔐 Check security…",
@@ -240,26 +244,34 @@ if check_password():
240
  "🧑‍🎓 Adapting to personality of Fernando…",
241
  "🚀 Almost ready…"
242
  ]
243
- placeholder = st.empty()
244
  try:
245
  # Request to backend
246
  i = 0
247
- while True:
248
- status = requests.get(API_URL + "/model_status").json()['status']
249
- if status == "not_initialized":
250
- requests.post(API_URL + "/load_model")
251
- elif status == "ready":
252
- break
253
-
254
- # some interactive placeholder
255
- placeholder.markdown(messages[i % len(messages)])
256
- i += 1
257
- time.sleep(3)
 
 
 
 
 
 
 
 
258
 
259
  placeholder.markdown("💬 Typing…")
260
  response = requests.post(API_URL +"/generate", json={"message": user_input, "history": st.session_state.history_submit, "fallback_counter": st.session_state.fallback_counter}, timeout=120)
261
  response.raise_for_status()
262
-
263
  # Get reply and show it
264
  st.session_state.history_submit = response.json().get("history", [])
265
  answer = response.json().get("reply", "")
 
99
  justify-content: center;
100
  align-items: center;
101
  z-index: 9999;
102
+ animation: fadeout 2s ease 5s forwards;
103
  }
104
 
105
  /* Text & Animation */
 
130
  st.markdown(splash_html, unsafe_allow_html=True)
131
  if requests.get(API_URL + "/model_status").json()['status'] != "ready":
132
  requests.post(API_URL + "/load_model")
133
+ time.sleep(5)
134
  st.session_state.splash_done = True
135
  st.rerun()
136
  else:
 
145
 
146
  if "fallback_counter" not in st.session_state:
147
  st.session_state.fallback_counter = 0
148
+
149
+ if "last_response_time" not in st.session_state:
150
+ st.session_state.last_response_time = 0
151
 
152
  st.markdown("""
153
  <style>
 
235
 
236
  with st.chat_message("assistant", avatar=avatar_path):
237
  messages = [
238
+ "⏳ Checking model status…",
239
  "🔄 Initializing application…",
240
  "📚 Loading memory…",
241
  "🔐 Check security…",
 
244
  "🧑‍🎓 Adapting to personality of Fernando…",
245
  "🚀 Almost ready…"
246
  ]
247
+
248
  try:
249
  # Request to backend
250
  i = 0
251
+ now = time.time()
252
+ elapsed = now - st.session_state.last_response_time
253
+ placeholder = st.empty()
254
+
255
+ # look after model status if
256
+ if elapsed > 45:
257
+ while True:
258
+ # some interactive placeholder
259
+ placeholder.markdown(messages[i % len(messages)])
260
+ status = requests.get(API_URL + "/model_status").json()['status']
261
+ print(status)
262
+ if status == "not_initialized":
263
+ requests.post(API_URL + "/load_model")
264
+ elif status == "ready":
265
+ i = 0
266
+ break
267
+
268
+ i += 1
269
+ time.sleep(2)
270
 
271
  placeholder.markdown("💬 Typing…")
272
  response = requests.post(API_URL +"/generate", json={"message": user_input, "history": st.session_state.history_submit, "fallback_counter": st.session_state.fallback_counter}, timeout=120)
273
  response.raise_for_status()
274
+ st.session_state.last_response_time = time.time()
275
  # Get reply and show it
276
  st.session_state.history_submit = response.json().get("history", [])
277
  answer = response.json().get("reply", "")