Spaces:
Paused
Paused
DISABLING CHAT UNTIL USER INPUT
Browse files
app.py
CHANGED
|
@@ -96,13 +96,13 @@ def initModel():
|
|
| 96 |
def start_chat(initial_issue, chat_history, context, support_type, session_id, request: gr.Request):
|
| 97 |
session_id = get_session_id(session_id, request)
|
| 98 |
initial_issue = (initial_issue or "").strip()
|
| 99 |
-
if not initial_issue
|
| 100 |
return (
|
| 101 |
chat_history, context, chat_history, session_id,
|
| 102 |
gr.update(), # initial textbox
|
| 103 |
gr.update(), # radio
|
| 104 |
gr.update(interactive=False), # followup textbox
|
| 105 |
-
gr.update() # start button
|
| 106 |
)
|
| 107 |
|
| 108 |
opening_response = (
|
|
@@ -295,7 +295,7 @@ with gr.Blocks() as demo:
|
|
| 295 |
label="Support type",
|
| 296 |
interactive=True
|
| 297 |
)
|
| 298 |
-
start_btn = gr.Button("Start")
|
| 299 |
chatbot = gr.Chatbot(label="Chat")
|
| 300 |
history_state = gr.State([])
|
| 301 |
context_state = gr.State("")
|
|
@@ -303,9 +303,13 @@ with gr.Blocks() as demo:
|
|
| 303 |
|
| 304 |
user_input = gr.Textbox(
|
| 305 |
label="Your message",
|
| 306 |
-
placeholder="Describe a stressful situation you need suggestions for"
|
|
|
|
| 307 |
)
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
| 309 |
def disable_support_type(text, locked, current_value):
|
| 310 |
if locked:
|
| 311 |
return gr.update(interactive=False, value=current_value), True
|
|
@@ -315,11 +319,18 @@ with gr.Blocks() as demo:
|
|
| 315 |
|
| 316 |
return gr.update(interactive=True, value=current_value), False
|
| 317 |
user_input.input(
|
| 318 |
-
|
| 319 |
-
inputs=[user_input,
|
| 320 |
-
outputs=[
|
| 321 |
queue=False
|
| 322 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
with gr.Row():
|
| 324 |
send_btn = gr.Button("Send")
|
| 325 |
|
|
|
|
| 96 |
def start_chat(initial_issue, chat_history, context, support_type, session_id, request: gr.Request):
|
| 97 |
session_id = get_session_id(session_id, request)
|
| 98 |
initial_issue = (initial_issue or "").strip()
|
| 99 |
+
if not initial_issue or not support_type:
|
| 100 |
return (
|
| 101 |
chat_history, context, chat_history, session_id,
|
| 102 |
gr.update(), # initial textbox
|
| 103 |
gr.update(), # radio
|
| 104 |
gr.update(interactive=False), # followup textbox
|
| 105 |
+
gr.update(interactive=True) # start button
|
| 106 |
)
|
| 107 |
|
| 108 |
opening_response = (
|
|
|
|
| 295 |
label="Support type",
|
| 296 |
interactive=True
|
| 297 |
)
|
| 298 |
+
start_btn = gr.Button("Start", interactive=False)
|
| 299 |
chatbot = gr.Chatbot(label="Chat")
|
| 300 |
history_state = gr.State([])
|
| 301 |
context_state = gr.State("")
|
|
|
|
| 303 |
|
| 304 |
user_input = gr.Textbox(
|
| 305 |
label="Your message",
|
| 306 |
+
placeholder="Describe a stressful situation you need suggestions for",
|
| 307 |
+
interactive = False
|
| 308 |
)
|
| 309 |
+
def toggle_start_button(initial_issue, support_type):
|
| 310 |
+
ready = bool((initial_issue or "").strip()) and bool(support_type)
|
| 311 |
+
return gr.update(interactive=ready)
|
| 312 |
+
|
| 313 |
def disable_support_type(text, locked, current_value):
|
| 314 |
if locked:
|
| 315 |
return gr.update(interactive=False, value=current_value), True
|
|
|
|
| 319 |
|
| 320 |
return gr.update(interactive=True, value=current_value), False
|
| 321 |
user_input.input(
|
| 322 |
+
toggle_start_button,
|
| 323 |
+
inputs=[user_input, support_type],
|
| 324 |
+
outputs=[start_btn],
|
| 325 |
queue=False
|
| 326 |
)
|
| 327 |
+
|
| 328 |
+
support_type.change(
|
| 329 |
+
toggle_start_button,
|
| 330 |
+
inputs=[initial_issue, support_type],
|
| 331 |
+
outputs=[start_btn],
|
| 332 |
+
queue=False
|
| 333 |
+
)
|
| 334 |
with gr.Row():
|
| 335 |
send_btn = gr.Button("Send")
|
| 336 |
|