toninio19 commited on
Commit
4d8fd2b
·
verified ·
1 Parent(s): b70e383

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -180,9 +180,9 @@ def create_arena_interface():
180
  left_button = gr.Button("👈 Left video looks better", size="lg")
181
  right_button = gr.Button("Right video looks better ", size="lg")
182
 
183
- # Replace the old passkey section with a hidden keyboard status
184
  with gr.Row(visible=False) as secret_row:
185
- keyboard_status = gr.Textbox(value="", label="Status", interactive=False)
186
 
187
  # Simplified tab structure - just the rankings tab (hidden by default)
188
  rankings_tab = gr.Tab("Current Rankings", visible=False)
@@ -258,27 +258,27 @@ def create_arena_interface():
258
  fn=reset_data, inputs=[], outputs=[reset_warning, reset_confirm, reset_button, rankings_table]
259
  )
260
 
261
- def check_secret_sequence(evt: gr.EventData) -> Dict:
262
- """Check if the pressed keys match the secret sequence."""
263
  # Get passkey from environment variable
264
  correct_passkey = os.environ.get("PASSKEY", "").lower()
265
 
266
- # Track the sequence in the component's value
267
- current_sequence = keyboard_status.value + evt.key.lower()
268
  # Keep only the last N characters where N is the length of the passkey
269
- current_sequence = current_sequence[-len(correct_passkey):]
270
 
271
  is_visible = current_sequence == correct_passkey
272
  return {
273
- keyboard_status: current_sequence,
274
  download_section: gr.Row(visible=is_visible),
275
  download_output: gr.File(visible=is_visible),
276
  rankings_tab: gr.Tab(visible=is_visible),
277
  }
278
 
279
- # Add keyboard event listener
280
- demo.load(lambda: "", outputs=[keyboard_status])
281
- demo.on("keydown", check_secret_sequence, outputs=[keyboard_status, download_section, download_output, rankings_tab])
 
 
 
282
 
283
  def load_new_comparison():
284
  """Load a new random comparison."""
 
180
  left_button = gr.Button("👈 Left video looks better", size="lg")
181
  right_button = gr.Button("Right video looks better ", size="lg")
182
 
183
+ # Replace the old passkey section with a hidden keyboard tracker
184
  with gr.Row(visible=False) as secret_row:
185
+ keyboard_status = gr.Textbox(value="", label="Status", interactive=True)
186
 
187
  # Simplified tab structure - just the rankings tab (hidden by default)
188
  rankings_tab = gr.Tab("Current Rankings", visible=False)
 
258
  fn=reset_data, inputs=[], outputs=[reset_warning, reset_confirm, reset_button, rankings_table]
259
  )
260
 
261
+ def check_secret_sequence(text: str) -> Dict:
262
+ """Check if the typed text matches the secret sequence."""
263
  # Get passkey from environment variable
264
  correct_passkey = os.environ.get("PASSKEY", "").lower()
265
 
 
 
266
  # Keep only the last N characters where N is the length of the passkey
267
+ current_sequence = text.lower()[-len(correct_passkey):]
268
 
269
  is_visible = current_sequence == correct_passkey
270
  return {
 
271
  download_section: gr.Row(visible=is_visible),
272
  download_output: gr.File(visible=is_visible),
273
  rankings_tab: gr.Tab(visible=is_visible),
274
  }
275
 
276
+ # Add change handler for the keyboard status
277
+ keyboard_status.change(
278
+ fn=check_secret_sequence,
279
+ inputs=[keyboard_status],
280
+ outputs=[download_section, download_output, rankings_tab],
281
+ )
282
 
283
  def load_new_comparison():
284
  """Load a new random comparison."""