Spaces:
Paused
Paused
unified functions
Browse files
app.py
CHANGED
|
@@ -280,6 +280,31 @@ def init_support_choices(request: gr.Request):
|
|
| 280 |
choices = list(MODE_INSTRUCTIONS.keys())
|
| 281 |
rng.shuffle(choices)
|
| 282 |
return choices, gr.update(choices=choices, value=None, interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
with gr.Blocks() as demo:
|
| 285 |
|
|
@@ -320,12 +345,7 @@ with gr.Blocks() as demo:
|
|
| 320 |
placeholder="Describe a stressful situation you need suggestions for",
|
| 321 |
interactive = False
|
| 322 |
)
|
| 323 |
-
|
| 324 |
-
ready = bool((initial_issue or "").strip()) and bool(support_type)
|
| 325 |
-
return gr.update(interactive=ready)
|
| 326 |
-
def toggle_send_button(user_input):
|
| 327 |
-
ready = bool((user_input or "").strip())
|
| 328 |
-
return gr.update(interactive=ready)
|
| 329 |
|
| 330 |
initial_issue.input(
|
| 331 |
toggle_start_button,
|
|
@@ -379,25 +399,7 @@ with gr.Blocks() as demo:
|
|
| 379 |
outputs=[user_input, chatbot, context_state, history_state, session_state, start_time_state, send_btn]
|
| 380 |
)
|
| 381 |
|
| 382 |
-
|
| 383 |
-
if start_time is None:
|
| 384 |
-
return gr.update(), gr.update(), ""
|
| 385 |
-
|
| 386 |
-
remaining = max(0, int(SESSION_LIMIT_SECONDS - (time.time() - start_time)))
|
| 387 |
-
expired = remaining <= 0
|
| 388 |
-
|
| 389 |
-
if expired:
|
| 390 |
-
return (
|
| 391 |
-
gr.update(interactive=False), # send_btn
|
| 392 |
-
gr.update(interactive=False), # user_input
|
| 393 |
-
"Time remaining: 0 seconds"
|
| 394 |
-
)
|
| 395 |
-
|
| 396 |
-
return (
|
| 397 |
-
gr.update(interactive=True), # send_btn
|
| 398 |
-
gr.update(interactive=True), # user_input
|
| 399 |
-
f"Time remaining: {remaining} seconds"
|
| 400 |
-
)
|
| 401 |
|
| 402 |
timer.tick(
|
| 403 |
disable_after_timeout,
|
|
|
|
| 280 |
choices = list(MODE_INSTRUCTIONS.keys())
|
| 281 |
rng.shuffle(choices)
|
| 282 |
return choices, gr.update(choices=choices, value=None, interactive=True)
|
| 283 |
+
def disable_after_timeout(start_time):
|
| 284 |
+
if start_time is None:
|
| 285 |
+
return gr.update(), gr.update(), ""
|
| 286 |
+
|
| 287 |
+
remaining = max(0, int(SESSION_LIMIT_SECONDS - (time.time() - start_time)))
|
| 288 |
+
expired = remaining <= 0
|
| 289 |
+
|
| 290 |
+
if expired:
|
| 291 |
+
return (
|
| 292 |
+
gr.update(interactive=False), # send_btn
|
| 293 |
+
gr.update(interactive=False), # user_input
|
| 294 |
+
"Time remaining: 0 seconds"
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
return (
|
| 298 |
+
gr.update(interactive=True), # send_btn
|
| 299 |
+
gr.update(interactive=True), # user_input
|
| 300 |
+
f"Time remaining: {remaining} seconds"
|
| 301 |
+
)
|
| 302 |
+
def toggle_start_button(initial_issue, support_type):
|
| 303 |
+
ready = bool((initial_issue or "").strip()) and bool(support_type)
|
| 304 |
+
return gr.update(interactive=ready)
|
| 305 |
+
def toggle_send_button(user_input):
|
| 306 |
+
ready = bool((user_input or "").strip())
|
| 307 |
+
return gr.update(interactive=ready)
|
| 308 |
|
| 309 |
with gr.Blocks() as demo:
|
| 310 |
|
|
|
|
| 345 |
placeholder="Describe a stressful situation you need suggestions for",
|
| 346 |
interactive = False
|
| 347 |
)
|
| 348 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
initial_issue.input(
|
| 351 |
toggle_start_button,
|
|
|
|
| 399 |
outputs=[user_input, chatbot, context_state, history_state, session_state, start_time_state, send_btn]
|
| 400 |
)
|
| 401 |
|
| 402 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
timer.tick(
|
| 405 |
disable_after_timeout,
|