Update app.py
Browse files
app.py
CHANGED
@@ -929,9 +929,7 @@ with gr.Blocks() as app:
|
|
929 |
|
930 |
# First round handling
|
931 |
send_first.click(
|
932 |
-
fn=hide_thanks_message,
|
933 |
-
inputs=[],
|
934 |
-
outputs=[thanks_message]
|
935 |
).then(
|
936 |
fn=disable_first_submit_ui, # First disable UI
|
937 |
inputs=[],
|
@@ -939,8 +937,8 @@ with gr.Blocks() as app:
|
|
939 |
guardrail_message,
|
940 |
shared_input,
|
941 |
repo_url,
|
942 |
-
send_first # Just the essential UI elements to update immediately
|
943 |
-
]
|
944 |
).then(
|
945 |
fn=update_model_titles_and_responses, # Then do the actual processing
|
946 |
inputs=[repo_url, shared_input, models_state, conversation_state],
|
@@ -972,7 +970,7 @@ with gr.Blocks() as app:
|
|
972 |
# [0] model_a_input: disable
|
973 |
gr.update(interactive=False),
|
974 |
# [1] model_a_send: disable and show loading state
|
975 |
-
gr.update(interactive=False, value="Processing...")
|
976 |
)
|
977 |
|
978 |
# Handle subsequent rounds
|
@@ -986,8 +984,12 @@ with gr.Blocks() as app:
|
|
986 |
response,
|
987 |
conversation_state,
|
988 |
gr.update(visible=False),
|
989 |
-
gr.update(
|
990 |
-
|
|
|
|
|
|
|
|
|
991 |
)
|
992 |
except TimeoutError as e:
|
993 |
# Disable inputs when timeout occurs
|
@@ -996,18 +998,22 @@ with gr.Blocks() as app:
|
|
996 |
conversation_state,
|
997 |
gr.update(visible=True), # Show the timeout popup
|
998 |
gr.update(interactive=True), # Re-enable model_a_input
|
999 |
-
gr.update(
|
|
|
|
|
1000 |
)
|
1001 |
except Exception as e:
|
1002 |
raise gr.Error(str(e))
|
|
|
1003 |
def disable_model_b_ui():
|
1004 |
"""First function to immediately disable model B UI elements"""
|
1005 |
return (
|
1006 |
# [0] model_b_input: disable
|
1007 |
gr.update(interactive=False),
|
1008 |
# [1] model_b_send: disable and show loading state
|
1009 |
-
gr.update(interactive=False, value="Processing...")
|
1010 |
)
|
|
|
1011 |
def handle_model_b_send(user_input, models_state, conversation_state):
|
1012 |
try:
|
1013 |
response = chat_with_models(
|
@@ -1018,8 +1024,12 @@ with gr.Blocks() as app:
|
|
1018 |
response,
|
1019 |
conversation_state,
|
1020 |
gr.update(visible=False),
|
1021 |
-
gr.update(
|
1022 |
-
|
|
|
|
|
|
|
|
|
1023 |
)
|
1024 |
except TimeoutError as e:
|
1025 |
# Disable inputs when timeout occurs
|
@@ -1028,7 +1038,9 @@ with gr.Blocks() as app:
|
|
1028 |
conversation_state,
|
1029 |
gr.update(visible=True), # Show the timeout popup
|
1030 |
gr.update(interactive=True), # Re-enable model_b_input
|
1031 |
-
gr.update(
|
|
|
|
|
1032 |
)
|
1033 |
except Exception as e:
|
1034 |
raise gr.Error(str(e))
|
@@ -1036,10 +1048,7 @@ with gr.Blocks() as app:
|
|
1036 |
model_a_send.click(
|
1037 |
fn=disable_model_a_ui, # First disable UI
|
1038 |
inputs=[],
|
1039 |
-
outputs=[
|
1040 |
-
model_a_input,
|
1041 |
-
model_a_send
|
1042 |
-
]
|
1043 |
).then(
|
1044 |
fn=handle_model_a_send, # Then do the actual processing
|
1045 |
inputs=[model_a_input, models_state, conversation_state],
|
@@ -1054,10 +1063,7 @@ with gr.Blocks() as app:
|
|
1054 |
model_b_send.click(
|
1055 |
fn=disable_model_b_ui, # First disable UI
|
1056 |
inputs=[],
|
1057 |
-
outputs=[
|
1058 |
-
model_b_input,
|
1059 |
-
model_b_send
|
1060 |
-
]
|
1061 |
).then(
|
1062 |
fn=handle_model_b_send, # Then do the actual processing
|
1063 |
inputs=[model_b_input, models_state, conversation_state],
|
|
|
929 |
|
930 |
# First round handling
|
931 |
send_first.click(
|
932 |
+
fn=hide_thanks_message, inputs=[], outputs=[thanks_message]
|
|
|
|
|
933 |
).then(
|
934 |
fn=disable_first_submit_ui, # First disable UI
|
935 |
inputs=[],
|
|
|
937 |
guardrail_message,
|
938 |
shared_input,
|
939 |
repo_url,
|
940 |
+
send_first, # Just the essential UI elements to update immediately
|
941 |
+
],
|
942 |
).then(
|
943 |
fn=update_model_titles_and_responses, # Then do the actual processing
|
944 |
inputs=[repo_url, shared_input, models_state, conversation_state],
|
|
|
970 |
# [0] model_a_input: disable
|
971 |
gr.update(interactive=False),
|
972 |
# [1] model_a_send: disable and show loading state
|
973 |
+
gr.update(interactive=False, value="Processing..."),
|
974 |
)
|
975 |
|
976 |
# Handle subsequent rounds
|
|
|
984 |
response,
|
985 |
conversation_state,
|
986 |
gr.update(visible=False),
|
987 |
+
gr.update(
|
988 |
+
value="", interactive=True
|
989 |
+
), # Clear and enable model_a_input
|
990 |
+
gr.update(
|
991 |
+
interactive=False, value="Send to Model A"
|
992 |
+
), # Reset button text
|
993 |
)
|
994 |
except TimeoutError as e:
|
995 |
# Disable inputs when timeout occurs
|
|
|
998 |
conversation_state,
|
999 |
gr.update(visible=True), # Show the timeout popup
|
1000 |
gr.update(interactive=True), # Re-enable model_a_input
|
1001 |
+
gr.update(
|
1002 |
+
interactive=True, value="Send to Model A"
|
1003 |
+
), # Re-enable model_a_send button
|
1004 |
)
|
1005 |
except Exception as e:
|
1006 |
raise gr.Error(str(e))
|
1007 |
+
|
1008 |
def disable_model_b_ui():
|
1009 |
"""First function to immediately disable model B UI elements"""
|
1010 |
return (
|
1011 |
# [0] model_b_input: disable
|
1012 |
gr.update(interactive=False),
|
1013 |
# [1] model_b_send: disable and show loading state
|
1014 |
+
gr.update(interactive=False, value="Processing..."),
|
1015 |
)
|
1016 |
+
|
1017 |
def handle_model_b_send(user_input, models_state, conversation_state):
|
1018 |
try:
|
1019 |
response = chat_with_models(
|
|
|
1024 |
response,
|
1025 |
conversation_state,
|
1026 |
gr.update(visible=False),
|
1027 |
+
gr.update(
|
1028 |
+
value="", interactive=True
|
1029 |
+
), # Clear and enable model_b_input
|
1030 |
+
gr.update(
|
1031 |
+
interactive=False, value="Send to Model B"
|
1032 |
+
), # Reset button text
|
1033 |
)
|
1034 |
except TimeoutError as e:
|
1035 |
# Disable inputs when timeout occurs
|
|
|
1038 |
conversation_state,
|
1039 |
gr.update(visible=True), # Show the timeout popup
|
1040 |
gr.update(interactive=True), # Re-enable model_b_input
|
1041 |
+
gr.update(
|
1042 |
+
interactive=True, value="Send to Model B"
|
1043 |
+
), # Re-enable model_b_send button
|
1044 |
)
|
1045 |
except Exception as e:
|
1046 |
raise gr.Error(str(e))
|
|
|
1048 |
model_a_send.click(
|
1049 |
fn=disable_model_a_ui, # First disable UI
|
1050 |
inputs=[],
|
1051 |
+
outputs=[model_a_input, model_a_send],
|
|
|
|
|
|
|
1052 |
).then(
|
1053 |
fn=handle_model_a_send, # Then do the actual processing
|
1054 |
inputs=[model_a_input, models_state, conversation_state],
|
|
|
1063 |
model_b_send.click(
|
1064 |
fn=disable_model_b_ui, # First disable UI
|
1065 |
inputs=[],
|
1066 |
+
outputs=[model_b_input, model_b_send],
|
|
|
|
|
|
|
1067 |
).then(
|
1068 |
fn=handle_model_b_send, # Then do the actual processing
|
1069 |
inputs=[model_b_input, models_state, conversation_state],
|