Spaces:
Running
Running
terryyz
commited on
Commit
Β·
48a3a23
1
Parent(s):
c833d3f
fix
Browse files
app.py
CHANGED
|
@@ -594,7 +594,11 @@ def add_text_and_generate(state0, state1, text, temperature, max_tokens, model_a
|
|
| 594 |
chat_stats_a = f"**Conversation:** {turn_count_a} turns | **Total Messages:** {len(state0['messages']) if state0 else 0}"
|
| 595 |
chat_stats_b = f"**Conversation:** {turn_count_b} turns | **Total Messages:** {len(state1['messages']) if state1 else 0}"
|
| 596 |
|
| 597 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
|
| 599 |
def format_chat_history(messages):
|
| 600 |
"""Format messages for chat display with turn numbers"""
|
|
@@ -649,6 +653,8 @@ def clear_chat(state0, state1):
|
|
| 649 |
"**Conversation:** 0 turns | **Total Messages:** 0", # chat_stats_b
|
| 650 |
"", # sandbox_view_a (duplicate)
|
| 651 |
"", # sandbox_view_b (duplicate)
|
|
|
|
|
|
|
| 652 |
f"**Model A:** {model_a}", # model_display_a
|
| 653 |
f"**Model B:** {model_b}", # model_display_b
|
| 654 |
"", # text_input
|
|
@@ -828,6 +834,8 @@ def send_to_left_only(state0, state1, text, temperature, max_tokens, model_a, mo
|
|
| 828 |
"", # sandbox_view_b (empty)
|
| 829 |
state0, # state0_var
|
| 830 |
state1, # state1_var
|
|
|
|
|
|
|
| 831 |
text, # Keep original text input
|
| 832 |
f"**Model A:** {model_a}", # Update model display A
|
| 833 |
f"**Model B:** {model_b}", # Update model display B
|
|
@@ -926,6 +934,8 @@ def send_to_right_only(state0, state1, text, temperature, max_tokens, model_a, m
|
|
| 926 |
sandbox_view_b, # sandbox_view_b
|
| 927 |
state0, # state0_var
|
| 928 |
state1, # state1_var
|
|
|
|
|
|
|
| 929 |
text, # Keep original text input
|
| 930 |
f"**Model A:** {model_a}", # Update model display A
|
| 931 |
f"**Model B:** {model_b}", # Update model display B
|
|
@@ -939,6 +949,42 @@ def send_to_right_only(state0, state1, text, temperature, max_tokens, model_a, m
|
|
| 939 |
)
|
| 940 |
|
| 941 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tuple[str, str, str]:
|
| 943 |
"""Run code in the appropriate sandbox environment"""
|
| 944 |
if not code.strip():
|
|
@@ -972,7 +1018,6 @@ def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tu
|
|
| 972 |
return result['sandbox_url'], "", result['stderr']
|
| 973 |
|
| 974 |
elif env == SandboxEnvironment.GRADIO:
|
| 975 |
-
print(f"DEBUG: running gradio sandbox")
|
| 976 |
sandbox_url, sandbox_id, stderr = run_gradio_sandbox(code, install_command, sandbox_state.get('sandbox_id'))
|
| 977 |
sandbox_state['sandbox_id'] = sandbox_id
|
| 978 |
return sandbox_url, "", stderr
|
|
@@ -990,7 +1035,6 @@ def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tu
|
|
| 990 |
return sandbox_url, "", stderr
|
| 991 |
|
| 992 |
elif env == SandboxEnvironment.PYTHON_RUNNER:
|
| 993 |
-
print(f"DEBUG: running python runner")
|
| 994 |
output, stderr = run_code_interpreter(code, 'python', install_command)
|
| 995 |
return "", output, stderr
|
| 996 |
|
|
@@ -1186,8 +1230,8 @@ def build_ui():
|
|
| 1186 |
# Model A Sandbox
|
| 1187 |
with gr.Column():
|
| 1188 |
gr.Markdown("### Model A Sandbox")
|
| 1189 |
-
with gr.Tabs():
|
| 1190 |
-
with gr.Tab("View"):
|
| 1191 |
sandbox_view_a = gr.Markdown(
|
| 1192 |
"**Sandbox output will appear here automatically**"
|
| 1193 |
)
|
|
@@ -1196,19 +1240,29 @@ def build_ui():
|
|
| 1196 |
label="Model A Sandbox",
|
| 1197 |
visible=False,
|
| 1198 |
)
|
| 1199 |
-
with gr.Tab("Code"):
|
| 1200 |
code_a = gr.Code(
|
| 1201 |
label="Extracted Code",
|
| 1202 |
language="python",
|
| 1203 |
lines=8,
|
| 1204 |
-
interactive=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1205 |
)
|
| 1206 |
|
| 1207 |
# Model B Sandbox
|
| 1208 |
with gr.Column():
|
| 1209 |
gr.Markdown("### Model B Sandbox")
|
| 1210 |
-
with gr.Tabs():
|
| 1211 |
-
with gr.Tab("View"):
|
| 1212 |
sandbox_view_b = gr.Markdown(
|
| 1213 |
"**Sandbox output will appear here automatically**"
|
| 1214 |
)
|
|
@@ -1217,12 +1271,22 @@ def build_ui():
|
|
| 1217 |
label="Model B Sandbox",
|
| 1218 |
visible=False,
|
| 1219 |
)
|
| 1220 |
-
with gr.Tab("Code"):
|
| 1221 |
code_b = gr.Code(
|
| 1222 |
label="Extracted Code",
|
| 1223 |
language="python",
|
| 1224 |
lines=8,
|
| 1225 |
-
interactive=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1226 |
)
|
| 1227 |
|
| 1228 |
# Vote UI components
|
|
@@ -1519,6 +1583,8 @@ def build_ui():
|
|
| 1519 |
result[19] if len(result) > 19 else "", # sandbox_view_b
|
| 1520 |
new_state0, # state0_var
|
| 1521 |
new_state1, # state1_var
|
|
|
|
|
|
|
| 1522 |
text, # Keep original text input
|
| 1523 |
f"**Model A:** {model_a}", # Update model display A
|
| 1524 |
f"**Model B:** {model_b}", # Update model display B
|
|
@@ -1563,6 +1629,8 @@ def build_ui():
|
|
| 1563 |
sandbox_view_b, # Sandbox view for model B
|
| 1564 |
state0_var, # Updated state for run button A
|
| 1565 |
state1_var, # Updated state for run button B
|
|
|
|
|
|
|
| 1566 |
text_input, # Clear the text input after sending
|
| 1567 |
model_display_a, # Update model display A
|
| 1568 |
model_display_b, # Update model display B
|
|
@@ -1609,6 +1677,8 @@ def build_ui():
|
|
| 1609 |
sandbox_view_b, # Sandbox view for model B
|
| 1610 |
state0_var, # Updated state for run button A
|
| 1611 |
state1_var, # Updated state for run button B
|
|
|
|
|
|
|
| 1612 |
text_input, # Clear the text input after sending
|
| 1613 |
model_display_a, # Update model display A
|
| 1614 |
model_display_b, # Update model display B
|
|
@@ -1652,6 +1722,8 @@ def build_ui():
|
|
| 1652 |
sandbox_view_b, # Sandbox view for model B
|
| 1653 |
state0_var, # Updated state for run button A
|
| 1654 |
state1_var, # Updated state for run button B
|
|
|
|
|
|
|
| 1655 |
text_input, # Clear the text input after sending
|
| 1656 |
model_display_a, # Update model display A
|
| 1657 |
model_display_b, # Update model display B
|
|
@@ -1698,6 +1770,8 @@ def build_ui():
|
|
| 1698 |
sandbox_view_b, # Sandbox view for model B
|
| 1699 |
state0_var, # Updated state for run button A
|
| 1700 |
state1_var, # Updated state for run button B
|
|
|
|
|
|
|
| 1701 |
text_input, # Clear the text input after sending
|
| 1702 |
model_display_a, # Update model display A
|
| 1703 |
model_display_b, # Update model display B
|
|
@@ -1744,6 +1818,8 @@ def build_ui():
|
|
| 1744 |
sandbox_view_b, # Sandbox view for model B
|
| 1745 |
state0_var, # Updated state for run button A
|
| 1746 |
state1_var, # Updated state for run button B
|
|
|
|
|
|
|
| 1747 |
text_input, # Clear the text input after sending
|
| 1748 |
model_display_a, # Update model display A
|
| 1749 |
model_display_b, # Update model display B
|
|
@@ -1779,6 +1855,10 @@ def build_ui():
|
|
| 1779 |
chat_stats_b, # Reset conversation statistics for model B
|
| 1780 |
sandbox_view_a, # Reset sandbox view for model A
|
| 1781 |
sandbox_view_b, # Reset sandbox view for model B
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1782 |
model_display_a, # Reset model display A
|
| 1783 |
model_display_b, # Reset model display B
|
| 1784 |
text_input, # Clear text input
|
|
@@ -1906,6 +1986,59 @@ def build_ui():
|
|
| 1906 |
"", # Clear text_input to preserve examples
|
| 1907 |
)
|
| 1908 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1909 |
# Vote button click handlers
|
| 1910 |
for vote_btn, vote_type in [
|
| 1911 |
(vote_left_btn, "left"),
|
|
|
|
| 594 |
chat_stats_a = f"**Conversation:** {turn_count_a} turns | **Total Messages:** {len(state0['messages']) if state0 else 0}"
|
| 595 |
chat_stats_b = f"**Conversation:** {turn_count_b} turns | **Total Messages:** {len(state1['messages']) if state1 else 0}"
|
| 596 |
|
| 597 |
+
# Get install commands from sandbox states
|
| 598 |
+
install_command0 = sandbox_state0.get('install_command', '') if sandbox_state0 else ''
|
| 599 |
+
install_command1 = sandbox_state1.get('install_command', '') if sandbox_state1 else ''
|
| 600 |
+
|
| 601 |
+
return state0, state1, chat0, chat1, response0, response1, code0, code1, env0, env1, sandbox_state0, sandbox_state1, sandbox_output0, sandbox_output1, sandbox_component_update0, sandbox_component_update1, chat_stats_a, chat_stats_b, sandbox_view_a, sandbox_view_b, install_command0, install_command1
|
| 602 |
|
| 603 |
def format_chat_history(messages):
|
| 604 |
"""Format messages for chat display with turn numbers"""
|
|
|
|
| 653 |
"**Conversation:** 0 turns | **Total Messages:** 0", # chat_stats_b
|
| 654 |
"", # sandbox_view_a (duplicate)
|
| 655 |
"", # sandbox_view_b (duplicate)
|
| 656 |
+
"", # install_command_a
|
| 657 |
+
"", # install_command_b
|
| 658 |
f"**Model A:** {model_a}", # model_display_a
|
| 659 |
f"**Model B:** {model_b}", # model_display_b
|
| 660 |
"", # text_input
|
|
|
|
| 834 |
"", # sandbox_view_b (empty)
|
| 835 |
state0, # state0_var
|
| 836 |
state1, # state1_var
|
| 837 |
+
state0.get('install_command', ''), # state0_install_command
|
| 838 |
+
state1.get('install_command', ''), # state1_install_command
|
| 839 |
text, # Keep original text input
|
| 840 |
f"**Model A:** {model_a}", # Update model display A
|
| 841 |
f"**Model B:** {model_b}", # Update model display B
|
|
|
|
| 934 |
sandbox_view_b, # sandbox_view_b
|
| 935 |
state0, # state0_var
|
| 936 |
state1, # state1_var
|
| 937 |
+
state0.get('install_command', ''), # state0_install_command
|
| 938 |
+
state1.get('install_command', ''), # state1_install_command
|
| 939 |
text, # Keep original text input
|
| 940 |
f"**Model A:** {model_a}", # Update model display A
|
| 941 |
f"**Model B:** {model_b}", # Update model display B
|
|
|
|
| 949 |
)
|
| 950 |
|
| 951 |
|
| 952 |
+
def rerun_code_execution(state, current_code: str, current_install_command: str, model_name: str) -> tuple[dict, str, str, str]:
|
| 953 |
+
"""Re-run code execution for a specific model using the current code and install command from the UI components"""
|
| 954 |
+
if not state or not state.get("sandbox_state"):
|
| 955 |
+
return state, "", "", ""
|
| 956 |
+
|
| 957 |
+
sandbox_state = state["sandbox_state"]
|
| 958 |
+
|
| 959 |
+
if not current_code.strip():
|
| 960 |
+
return state, "", "", "No code to re-run"
|
| 961 |
+
|
| 962 |
+
# Update the sandbox state with the current code and install command
|
| 963 |
+
sandbox_state['code_to_execute'] = current_code
|
| 964 |
+
sandbox_state['install_command'] = current_install_command
|
| 965 |
+
|
| 966 |
+
# Re-run the code execution with the updated code and install command
|
| 967 |
+
sandbox_url, sandbox_output, sandbox_error = run_sandbox_code(sandbox_state, current_code, current_install_command)
|
| 968 |
+
|
| 969 |
+
# Update sandbox view with new output
|
| 970 |
+
sandbox_view = ""
|
| 971 |
+
if sandbox_output:
|
| 972 |
+
sandbox_view += sandbox_output
|
| 973 |
+
if sandbox_error:
|
| 974 |
+
sandbox_view = f"<details closed><summary><strong>π¨ Errors/Warnings</strong></summary>\n\n```\n{sandbox_error}\n```\n\n</details>\n\n" + sandbox_view
|
| 975 |
+
|
| 976 |
+
# Update sandbox component if we have a URL
|
| 977 |
+
sandbox_component_update = None
|
| 978 |
+
if sandbox_url:
|
| 979 |
+
sandbox_component_update = gr.update(
|
| 980 |
+
value=(sandbox_url, True, []),
|
| 981 |
+
visible=True,
|
| 982 |
+
key=f"sandbox_{model_name.lower()}_{int(time.time() * 1000)}" # Unique key to force refresh
|
| 983 |
+
)
|
| 984 |
+
|
| 985 |
+
return state, sandbox_view, sandbox_component_update, sandbox_error
|
| 986 |
+
|
| 987 |
+
|
| 988 |
def run_sandbox_code(sandbox_state: dict, code: str, install_command: str) -> tuple[str, str, str]:
|
| 989 |
"""Run code in the appropriate sandbox environment"""
|
| 990 |
if not code.strip():
|
|
|
|
| 1018 |
return result['sandbox_url'], "", result['stderr']
|
| 1019 |
|
| 1020 |
elif env == SandboxEnvironment.GRADIO:
|
|
|
|
| 1021 |
sandbox_url, sandbox_id, stderr = run_gradio_sandbox(code, install_command, sandbox_state.get('sandbox_id'))
|
| 1022 |
sandbox_state['sandbox_id'] = sandbox_id
|
| 1023 |
return sandbox_url, "", stderr
|
|
|
|
| 1035 |
return sandbox_url, "", stderr
|
| 1036 |
|
| 1037 |
elif env == SandboxEnvironment.PYTHON_RUNNER:
|
|
|
|
| 1038 |
output, stderr = run_code_interpreter(code, 'python', install_command)
|
| 1039 |
return "", output, stderr
|
| 1040 |
|
|
|
|
| 1230 |
# Model A Sandbox
|
| 1231 |
with gr.Column():
|
| 1232 |
gr.Markdown("### Model A Sandbox")
|
| 1233 |
+
with gr.Tabs() as tabs_a:
|
| 1234 |
+
with gr.Tab("View", id=0):
|
| 1235 |
sandbox_view_a = gr.Markdown(
|
| 1236 |
"**Sandbox output will appear here automatically**"
|
| 1237 |
)
|
|
|
|
| 1240 |
label="Model A Sandbox",
|
| 1241 |
visible=False,
|
| 1242 |
)
|
| 1243 |
+
with gr.Tab("Code", id=1):
|
| 1244 |
code_a = gr.Code(
|
| 1245 |
label="Extracted Code",
|
| 1246 |
language="python",
|
| 1247 |
lines=8,
|
| 1248 |
+
interactive=True,
|
| 1249 |
+
)
|
| 1250 |
+
install_command_a = gr.Textbox(
|
| 1251 |
+
label="Install Command",
|
| 1252 |
+
placeholder="bash command to install dependencies",
|
| 1253 |
+
interactive=True,
|
| 1254 |
+
lines=1,
|
| 1255 |
+
)
|
| 1256 |
+
rerun_code_a_btn = gr.Button(
|
| 1257 |
+
"π Re-run Code",
|
| 1258 |
+
variant="huggingface",
|
| 1259 |
)
|
| 1260 |
|
| 1261 |
# Model B Sandbox
|
| 1262 |
with gr.Column():
|
| 1263 |
gr.Markdown("### Model B Sandbox")
|
| 1264 |
+
with gr.Tabs() as tabs_b:
|
| 1265 |
+
with gr.Tab("View", id=2):
|
| 1266 |
sandbox_view_b = gr.Markdown(
|
| 1267 |
"**Sandbox output will appear here automatically**"
|
| 1268 |
)
|
|
|
|
| 1271 |
label="Model B Sandbox",
|
| 1272 |
visible=False,
|
| 1273 |
)
|
| 1274 |
+
with gr.Tab("Code", id=3):
|
| 1275 |
code_b = gr.Code(
|
| 1276 |
label="Extracted Code",
|
| 1277 |
language="python",
|
| 1278 |
lines=8,
|
| 1279 |
+
interactive=True,
|
| 1280 |
+
)
|
| 1281 |
+
install_command_b = gr.Textbox(
|
| 1282 |
+
label="Install Command",
|
| 1283 |
+
placeholder="bash command to install dependencies",
|
| 1284 |
+
interactive=True,
|
| 1285 |
+
lines=1,
|
| 1286 |
+
)
|
| 1287 |
+
rerun_code_b_btn = gr.Button(
|
| 1288 |
+
"π Re-run Code",
|
| 1289 |
+
size="huggingface"
|
| 1290 |
)
|
| 1291 |
|
| 1292 |
# Vote UI components
|
|
|
|
| 1583 |
result[19] if len(result) > 19 else "", # sandbox_view_b
|
| 1584 |
new_state0, # state0_var
|
| 1585 |
new_state1, # state1_var
|
| 1586 |
+
new_state0.get('install_command', ''), # state0_install_command
|
| 1587 |
+
new_state1.get('install_command', ''), # state1_install_command
|
| 1588 |
text, # Keep original text input
|
| 1589 |
f"**Model A:** {model_a}", # Update model display A
|
| 1590 |
f"**Model B:** {model_b}", # Update model display B
|
|
|
|
| 1629 |
sandbox_view_b, # Sandbox view for model B
|
| 1630 |
state0_var, # Updated state for run button A
|
| 1631 |
state1_var, # Updated state for run button B
|
| 1632 |
+
install_command_a, # Install command for model A
|
| 1633 |
+
install_command_b, # Install command for model B
|
| 1634 |
text_input, # Clear the text input after sending
|
| 1635 |
model_display_a, # Update model display A
|
| 1636 |
model_display_b, # Update model display B
|
|
|
|
| 1677 |
sandbox_view_b, # Sandbox view for model B
|
| 1678 |
state0_var, # Updated state for run button A
|
| 1679 |
state1_var, # Updated state for run button B
|
| 1680 |
+
install_command_a, # Install command for model A
|
| 1681 |
+
install_command_b, # Install command for model B
|
| 1682 |
text_input, # Clear the text input after sending
|
| 1683 |
model_display_a, # Update model display A
|
| 1684 |
model_display_b, # Update model display B
|
|
|
|
| 1722 |
sandbox_view_b, # Sandbox view for model B
|
| 1723 |
state0_var, # Updated state for run button A
|
| 1724 |
state1_var, # Updated state for run button B
|
| 1725 |
+
install_command_a, # Install command for model A
|
| 1726 |
+
install_command_b, # Install command for model B
|
| 1727 |
text_input, # Clear the text input after sending
|
| 1728 |
model_display_a, # Update model display A
|
| 1729 |
model_display_b, # Update model display B
|
|
|
|
| 1770 |
sandbox_view_b, # Sandbox view for model B
|
| 1771 |
state0_var, # Updated state for run button A
|
| 1772 |
state1_var, # Updated state for run button B
|
| 1773 |
+
install_command_a, # Install command for model A
|
| 1774 |
+
install_command_b, # Install command for model B
|
| 1775 |
text_input, # Clear the text input after sending
|
| 1776 |
model_display_a, # Update model display A
|
| 1777 |
model_display_b, # Update model display B
|
|
|
|
| 1818 |
sandbox_view_b, # Sandbox view for model B
|
| 1819 |
state0_var, # Updated state for run button A
|
| 1820 |
state1_var, # Updated state for run button B
|
| 1821 |
+
install_command_a, # Install command for model A
|
| 1822 |
+
install_command_b, # Install command for model B
|
| 1823 |
text_input, # Clear the text input after sending
|
| 1824 |
model_display_a, # Update model display A
|
| 1825 |
model_display_b, # Update model display B
|
|
|
|
| 1855 |
chat_stats_b, # Reset conversation statistics for model B
|
| 1856 |
sandbox_view_a, # Reset sandbox view for model A
|
| 1857 |
sandbox_view_b, # Reset sandbox view for model B
|
| 1858 |
+
state0_var, # Updated state for run button A
|
| 1859 |
+
state1_var, # Updated state for run button B
|
| 1860 |
+
install_command_a, # Clear install command for model A
|
| 1861 |
+
install_command_b, # Clear install command for model B
|
| 1862 |
model_display_a, # Reset model display A
|
| 1863 |
model_display_b, # Reset model display B
|
| 1864 |
text_input, # Clear text input
|
|
|
|
| 1986 |
"", # Clear text_input to preserve examples
|
| 1987 |
)
|
| 1988 |
|
| 1989 |
+
# Re-run code button handlers
|
| 1990 |
+
def rerun_code_a(state0, current_code_a, current_install_command_a):
|
| 1991 |
+
"""Re-run code execution for Model A"""
|
| 1992 |
+
updated_state, sandbox_view, sandbox_component_update, error = rerun_code_execution(state0, current_code_a, current_install_command_a, "A")
|
| 1993 |
+
return (
|
| 1994 |
+
updated_state, # state0_var
|
| 1995 |
+
sandbox_view, # sandbox_view_a
|
| 1996 |
+
sandbox_component_update if sandbox_component_update else gr.skip(), # sandbox_component_a
|
| 1997 |
+
)
|
| 1998 |
+
|
| 1999 |
+
def rerun_code_b(state1, current_code_b, current_install_command_b):
|
| 2000 |
+
"""Re-run code execution for Model B"""
|
| 2001 |
+
updated_state, sandbox_view, sandbox_component_update, error = rerun_code_execution(state1, current_code_b, current_install_command_b, "B")
|
| 2002 |
+
return (
|
| 2003 |
+
updated_state, # state1_var
|
| 2004 |
+
sandbox_view, # sandbox_view_b
|
| 2005 |
+
sandbox_component_update if sandbox_component_update else gr.skip(), # sandbox_component_b
|
| 2006 |
+
)
|
| 2007 |
+
|
| 2008 |
+
def change_to_view_a():
|
| 2009 |
+
return gr.Tabs(selected=0)
|
| 2010 |
+
|
| 2011 |
+
def change_to_view_b():
|
| 2012 |
+
return gr.Tabs(selected=2)
|
| 2013 |
+
|
| 2014 |
+
rerun_code_a_btn.click(
|
| 2015 |
+
fn=change_to_view_a,
|
| 2016 |
+
inputs=[],
|
| 2017 |
+
outputs=[tabs_a]
|
| 2018 |
+
).then(
|
| 2019 |
+
fn=rerun_code_a,
|
| 2020 |
+
inputs=[state0_var, code_a, install_command_a],
|
| 2021 |
+
outputs=[
|
| 2022 |
+
state0_var, # state0_var
|
| 2023 |
+
sandbox_view_a, # sandbox_view_a
|
| 2024 |
+
sandbox_component_a, # sandbox_component_a
|
| 2025 |
+
]
|
| 2026 |
+
)
|
| 2027 |
+
|
| 2028 |
+
rerun_code_b_btn.click(
|
| 2029 |
+
fn=change_to_view_b,
|
| 2030 |
+
inputs=[],
|
| 2031 |
+
outputs=[tabs_b]
|
| 2032 |
+
).then(
|
| 2033 |
+
fn=rerun_code_b,
|
| 2034 |
+
inputs=[state1_var, code_b, install_command_b],
|
| 2035 |
+
outputs=[
|
| 2036 |
+
state1_var, # state1_var
|
| 2037 |
+
sandbox_view_b, # sandbox_view_b
|
| 2038 |
+
sandbox_component_b, # sandbox_component_b
|
| 2039 |
+
]
|
| 2040 |
+
)
|
| 2041 |
+
|
| 2042 |
# Vote button click handlers
|
| 2043 |
for vote_btn, vote_type in [
|
| 2044 |
(vote_left_btn, "left"),
|