terryyz commited on
Commit
47c72f8
·
1 Parent(s): aa2b984
Files changed (1) hide show
  1. app.py +51 -20
app.py CHANGED
@@ -1168,9 +1168,6 @@ def instantiate_clear_button():
1168
  def build_ui():
1169
  """Build a UI for the coding arena with integrated sandbox"""
1170
 
1171
- # Get random models for this session
1172
- model_a, model_b = get_random_models()
1173
- print(f"Model A: {model_a}, Model B: {model_b}")
1174
  with gr.Blocks(title="BigCodeArena", theme=gr.themes.Soft()) as demo:
1175
  # Add custom CSS for centering and button styling
1176
  demo.css = """
@@ -1224,11 +1221,11 @@ def build_ui():
1224
  with gr.Row():
1225
  with gr.Column():
1226
  model_display_a = gr.Markdown(
1227
- f"**Model A:** {model_a}", visible=False
1228
  )
1229
  with gr.Column():
1230
  model_display_b = gr.Markdown(
1231
- f"**Model B:** {model_b}", visible=False
1232
  )
1233
 
1234
  # Sandbox section with tabs for each model - Collapsible and open by default
@@ -1534,6 +1531,10 @@ def build_ui():
1534
  # Create state variables for the run buttons
1535
  state0_var = gr.State()
1536
  state1_var = gr.State()
 
 
 
 
1537
 
1538
  # Add telemetry logging for user interactions after state variables are created
1539
  # We need to create a wrapper function to extract the sandbox state from the main state
@@ -1647,8 +1648,8 @@ def build_ui():
1647
  text_input,
1648
  temperature,
1649
  max_tokens,
1650
- gr.State(model_a), # Use fixed model A
1651
- gr.State(model_b), # Use fixed model B
1652
  ],
1653
  outputs=[
1654
  state0_var, # state0
@@ -1695,8 +1696,8 @@ def build_ui():
1695
  text_input,
1696
  temperature,
1697
  max_tokens,
1698
- gr.State(model_a), # Use fixed model A
1699
- gr.State(model_b), # Use fixed model B
1700
  ],
1701
  outputs=[
1702
  state0_var, # state0
@@ -1740,8 +1741,8 @@ def build_ui():
1740
  inputs=[
1741
  state0_var, # state0
1742
  state1_var, # state1
1743
- gr.State(model_a), # Use fixed model A
1744
- gr.State(model_b), # Use fixed model B
1745
  ],
1746
  outputs=[
1747
  state0_var, # state0
@@ -1788,8 +1789,8 @@ def build_ui():
1788
  text_input,
1789
  temperature,
1790
  max_tokens,
1791
- gr.State(model_a), # Use fixed model A
1792
- gr.State(model_b), # Use fixed model B
1793
  ],
1794
  outputs=[
1795
  state0_var, # state0
@@ -1836,8 +1837,8 @@ def build_ui():
1836
  text_input,
1837
  temperature,
1838
  max_tokens,
1839
- gr.State(model_a), # Use fixed model A
1840
- gr.State(model_b), # Use fixed model B
1841
  ],
1842
  outputs=[
1843
  state0_var, # state0
@@ -1917,6 +1918,7 @@ def build_ui():
1917
  # Refresh models button handler
1918
  def refresh_models():
1919
  new_model_a, new_model_b = get_random_models()
 
1920
  return (
1921
  None, # Reset state0
1922
  None, # Reset state1
@@ -1943,6 +1945,8 @@ def build_ui():
1943
  gr.update(visible=False), # Hide vote section
1944
  gr.update(visible=False), # Hide vote buttons
1945
  gr.update(visible=False), # Clear vote status
 
 
1946
  )
1947
 
1948
  refresh_models_btn.click(
@@ -1974,6 +1978,8 @@ def build_ui():
1974
  vote_section, # Hide vote section
1975
  vote_buttons_row, # Hide vote buttons
1976
  vote_status, # Clear vote status
 
 
1977
  ],
1978
  )
1979
 
@@ -1995,7 +2001,8 @@ def build_ui():
1995
  gr.Info(f"Now you can see model names! 👀", duration=20)
1996
 
1997
  # Get new random models for the next session
1998
- model_a, model_b = get_random_models()
 
1999
 
2000
  # Clear everything and start fresh immediately, but preserve examples
2001
  return (
@@ -2027,6 +2034,8 @@ def build_ui():
2027
  gr.update(interactive=False), # Disable vote_tie_btn
2028
  gr.update(interactive=False), # Disable vote_both_bad_btn
2029
  "", # Clear text_input to preserve examples
 
 
2030
  )
2031
 
2032
  # Re-run code button handlers
@@ -2121,20 +2130,42 @@ def build_ui():
2121
  vote_tie_btn, # vote_tie_btn
2122
  vote_both_bad_btn, # vote_both_bad_btn
2123
  text_input, # text_input (to preserve examples)
 
 
2124
  ],
2125
  )
2126
 
2127
  # Setup ranking handlers
2128
  setup_ranking_handlers(demo, ranking_table, ranking_last_update, ranking_timer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2129
 
2130
  return demo
2131
 
2132
  def main():
2133
  """Main function to run the Simple BigCodeArena app"""
2134
- # Get random models for this session
2135
- model_a, model_b = get_random_models()
2136
-
2137
- # Build the UI
2138
  demo = build_ui()
2139
 
2140
  # Launch the app
 
1168
  def build_ui():
1169
  """Build a UI for the coding arena with integrated sandbox"""
1170
 
 
 
 
1171
  with gr.Blocks(title="BigCodeArena", theme=gr.themes.Soft()) as demo:
1172
  # Add custom CSS for centering and button styling
1173
  demo.css = """
 
1221
  with gr.Row():
1222
  with gr.Column():
1223
  model_display_a = gr.Markdown(
1224
+ "**Model A:** Loading...", visible=False
1225
  )
1226
  with gr.Column():
1227
  model_display_b = gr.Markdown(
1228
+ "**Model B:** Loading...", visible=False
1229
  )
1230
 
1231
  # Sandbox section with tabs for each model - Collapsible and open by default
 
1531
  # Create state variables for the run buttons
1532
  state0_var = gr.State()
1533
  state1_var = gr.State()
1534
+
1535
+ # Create state variables for model names - initialized per user session
1536
+ model_a_state = gr.State()
1537
+ model_b_state = gr.State()
1538
 
1539
  # Add telemetry logging for user interactions after state variables are created
1540
  # We need to create a wrapper function to extract the sandbox state from the main state
 
1648
  text_input,
1649
  temperature,
1650
  max_tokens,
1651
+ model_a_state, # Use per-user model A
1652
+ model_b_state, # Use per-user model B
1653
  ],
1654
  outputs=[
1655
  state0_var, # state0
 
1696
  text_input,
1697
  temperature,
1698
  max_tokens,
1699
+ model_a_state, # Use per-user model A
1700
+ model_b_state, # Use per-user model B
1701
  ],
1702
  outputs=[
1703
  state0_var, # state0
 
1741
  inputs=[
1742
  state0_var, # state0
1743
  state1_var, # state1
1744
+ model_a_state, # Use per-user model A
1745
+ model_b_state, # Use per-user model B
1746
  ],
1747
  outputs=[
1748
  state0_var, # state0
 
1789
  text_input,
1790
  temperature,
1791
  max_tokens,
1792
+ model_a_state, # Use per-user model A
1793
+ model_b_state, # Use per-user model B
1794
  ],
1795
  outputs=[
1796
  state0_var, # state0
 
1837
  text_input,
1838
  temperature,
1839
  max_tokens,
1840
+ model_a_state, # Use per-user model A
1841
+ model_b_state, # Use per-user model B
1842
  ],
1843
  outputs=[
1844
  state0_var, # state0
 
1918
  # Refresh models button handler
1919
  def refresh_models():
1920
  new_model_a, new_model_b = get_random_models()
1921
+ print(f"Refresh models - Model A: {new_model_a}, Model B: {new_model_b}")
1922
  return (
1923
  None, # Reset state0
1924
  None, # Reset state1
 
1945
  gr.update(visible=False), # Hide vote section
1946
  gr.update(visible=False), # Hide vote buttons
1947
  gr.update(visible=False), # Clear vote status
1948
+ new_model_a, # Update model_a_state
1949
+ new_model_b, # Update model_b_state
1950
  )
1951
 
1952
  refresh_models_btn.click(
 
1978
  vote_section, # Hide vote section
1979
  vote_buttons_row, # Hide vote buttons
1980
  vote_status, # Clear vote status
1981
+ model_a_state, # Update model_a_state
1982
+ model_b_state, # Update model_b_state
1983
  ],
1984
  )
1985
 
 
2001
  gr.Info(f"Now you can see model names! 👀", duration=20)
2002
 
2003
  # Get new random models for the next session
2004
+ new_model_a, new_model_b = get_random_models()
2005
+ print(f"Post-vote new models - Model A: {new_model_a}, Model B: {new_model_b}")
2006
 
2007
  # Clear everything and start fresh immediately, but preserve examples
2008
  return (
 
2034
  gr.update(interactive=False), # Disable vote_tie_btn
2035
  gr.update(interactive=False), # Disable vote_both_bad_btn
2036
  "", # Clear text_input to preserve examples
2037
+ new_model_a, # Update model_a_state with new model
2038
+ new_model_b, # Update model_b_state with new model
2039
  )
2040
 
2041
  # Re-run code button handlers
 
2130
  vote_tie_btn, # vote_tie_btn
2131
  vote_both_bad_btn, # vote_both_bad_btn
2132
  text_input, # text_input (to preserve examples)
2133
+ model_a_state, # Update model_a_state with new model
2134
+ model_b_state, # Update model_b_state with new model
2135
  ],
2136
  )
2137
 
2138
  # Setup ranking handlers
2139
  setup_ranking_handlers(demo, ranking_table, ranking_last_update, ranking_timer)
2140
+
2141
+ # Initialize random models for each user session when they load the page
2142
+ def init_models():
2143
+ """Initialize random models for this user session"""
2144
+ model_a, model_b = get_random_models()
2145
+ print(f"New user session - Model A: {model_a}, Model B: {model_b}")
2146
+ return (
2147
+ model_a, # model_a_state
2148
+ model_b, # model_b_state
2149
+ f"**Model A:** {model_a}", # model_display_a
2150
+ f"**Model B:** {model_b}", # model_display_b
2151
+ )
2152
+
2153
+ demo.load(
2154
+ fn=init_models,
2155
+ inputs=[],
2156
+ outputs=[
2157
+ model_a_state,
2158
+ model_b_state,
2159
+ model_display_a,
2160
+ model_display_b,
2161
+ ]
2162
+ )
2163
 
2164
  return demo
2165
 
2166
  def main():
2167
  """Main function to run the Simple BigCodeArena app"""
2168
+ # Build the UI - models are now selected per user session
 
 
 
2169
  demo = build_ui()
2170
 
2171
  # Launch the app