yixuantt commited on
Commit
6a3fd10
·
verified ·
1 Parent(s): 2e6a46f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -32
app.py CHANGED
@@ -197,7 +197,7 @@ forms_questions = {
197
  ],
198
  "Algorithmic Aversion": [
199
  # Trust in LLM
200
- {"question": "I trust the answers provided by AI chatbots (e.g., ChatGPT, Grok) to be accurate.", "options": ["Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]},
201
  {"question": "I feel confident relying on an AI chatbot for important tasks.", "options": ["Strongly Disagree", "Disagree", "Neutral", " Agree", "Strongly Agree"]},
202
  {"question": "I worry that AI chatbots might give me incorrect information.", "options": ["Strongly Disagree", "Disagree", "Neutral", " Agree", "Strongly Agree"]},
203
 
@@ -266,7 +266,7 @@ def create_interface():
266
 
267
  # New Forms Section
268
  with gr.Column(visible=False, elem_id="forms_section") as forms_section:
269
- gr.Markdown("## Post-Test Questions")
270
  gr.Markdown("Please answer the following questions to complete the study.")
271
  form_radios = []
272
  for form_name, questions in forms_questions.items():
@@ -299,8 +299,8 @@ def create_interface():
299
  if next_key is None:
300
  return {
301
  id_section: gr.update(visible=True),
302
- main_interface: gr.update(visible=False),
303
  forms_section: gr.update(visible=False),
 
304
  completion_section: gr.update(visible=False),
305
  id_message: gr.update(value="The study is full. Thank you for your interest.", visible=True)
306
  }
@@ -313,47 +313,47 @@ def create_interface():
313
  state.selected_indices = assignments[assignment_key]
314
  data = load_latest_data(prolific_id)
315
  if data:
316
- if state.forms_completed:
317
  return {
318
  id_section: gr.update(visible=False),
 
319
  main_interface: gr.update(visible=False),
320
- forms_section: gr.update(visible=False),
321
- completion_section: gr.update(visible=True),
322
  id_message: gr.update(value="", visible=False)
323
  }
324
- elif state.current_idx >= 28:
325
  return {
326
  id_section: gr.update(visible=False),
327
- main_interface: gr.update(visible=False),
328
- forms_section: gr.update(visible=True),
329
  completion_section: gr.update(visible=False),
330
- id_message: gr.update(value="", visible=False)
 
331
  }
332
  else:
333
  return {
334
  id_section: gr.update(visible=False),
335
- main_interface: gr.update(visible=True),
336
  forms_section: gr.update(visible=False),
337
- completion_section: gr.update(visible=False),
338
- id_message: gr.update(value="", visible=False),
339
- **update_interface(state.current_idx)
340
  }
341
  else:
342
  state.annotations = [None] * 28
343
  state.current_idx = 0
 
 
344
  return {
345
  id_section: gr.update(visible=False),
346
- main_interface: gr.update(visible=True),
347
- forms_section: gr.update(visible=False),
348
  completion_section: gr.update(visible=False),
349
- id_message: gr.update(value="", visible=False),
350
- **update_interface(0)
351
  }
352
-
353
  # Updated update_interface to use selected_indices
354
  def update_interface(current_idx):
355
  if current_idx >= 28:
356
- current_idx = 39
357
  actual_idx = state.selected_indices[current_idx]
358
  current_data = response_pairs[actual_idx]
359
  progress = f"**Progress:** {current_idx/28:.0%} ({min(current_idx, 28)}/28)"
@@ -380,7 +380,6 @@ def create_interface():
380
  gr.Warning(error_msg)
381
  return {
382
  main_interface: gr.update(visible=True),
383
- forms_section: gr.update(visible=False),
384
  completion_section: gr.update(visible=False),
385
  **update_interface(state.current_idx)
386
  }
@@ -404,14 +403,12 @@ def create_interface():
404
  if new_idx >= 28:
405
  return {
406
  main_interface: gr.update(visible=False),
407
- forms_section: gr.update(visible=True),
408
- completion_section: gr.update(visible=False),
409
- **update_interface(39) # Keep last question state
410
  }
411
  else:
412
  return {
413
  main_interface: gr.update(visible=True),
414
- forms_section: gr.update(visible=False),
415
  completion_section: gr.update(visible=False),
416
  **update_interface(new_idx)
417
  }
@@ -430,44 +427,48 @@ def create_interface():
430
  # New function to handle form submission
431
  def handle_forms_submit(*form_inputs):
432
  if any(input_val is None for input_val in form_inputs):
433
- gr.Warning("Please answer all questions before submitting.")
434
  return {
435
  forms_section: gr.update(visible=True),
 
436
  completion_section: gr.update(visible=False)
437
  }
438
  state.form_responses = {}
439
  idx = 0
440
  for form_name, questions in forms_questions.items():
441
  for q in questions:
442
- key = f"{form_name}_{q['question']}" # Convert tuple to string
443
  state.form_responses[key] = form_inputs[idx]
444
  idx += 1
445
  state.forms_completed = True
446
  save_annotations()
 
447
  return {
448
  forms_section: gr.update(visible=False),
449
- completion_section: gr.update(visible=True)
 
 
450
  }
451
 
452
  # Event bindings
453
  id_submit_btn.click(
454
  handle_id_submit,
455
  inputs=prolific_id,
456
- outputs=[id_section, main_interface, forms_section, completion_section, id_message, prompt_box,
457
  response_a, response_b, progress_md, feedback, confidence, selection_radio]
458
  )
459
 
460
  prev_btn.click(
461
  handle_navigation,
462
  inputs=[gr.State("prev"), selection_radio, confidence, feedback],
463
- outputs=[main_interface, forms_section, completion_section, prompt_box, response_a,
464
  response_b, progress_md, feedback, confidence, selection_radio]
465
  )
466
 
467
  next_btn.click(
468
  handle_navigation,
469
  inputs=[gr.State("next"), selection_radio, confidence, feedback],
470
- outputs=[main_interface, forms_section, completion_section, prompt_box, response_a,
471
  response_b, progress_md, feedback, confidence, selection_radio]
472
  )
473
 
@@ -481,7 +482,8 @@ def create_interface():
481
  submit_forms_btn.click(
482
  handle_forms_submit,
483
  inputs=form_radios,
484
- outputs=[forms_section, completion_section]
 
485
  )
486
 
487
  return demo
 
197
  ],
198
  "Algorithmic Aversion": [
199
  # Trust in LLM
200
+ {"question": "I trust the answers provided by AI chatbots (e.g., ChatGPT) to be accurate.", "options": ["Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]},
201
  {"question": "I feel confident relying on an AI chatbot for important tasks.", "options": ["Strongly Disagree", "Disagree", "Neutral", " Agree", "Strongly Agree"]},
202
  {"question": "I worry that AI chatbots might give me incorrect information.", "options": ["Strongly Disagree", "Disagree", "Neutral", " Agree", "Strongly Agree"]},
203
 
 
266
 
267
  # New Forms Section
268
  with gr.Column(visible=False, elem_id="forms_section") as forms_section:
269
+ gr.Markdown("## Pre-Test Questions")
270
  gr.Markdown("Please answer the following questions to complete the study.")
271
  form_radios = []
272
  for form_name, questions in forms_questions.items():
 
299
  if next_key is None:
300
  return {
301
  id_section: gr.update(visible=True),
 
302
  forms_section: gr.update(visible=False),
303
+ main_interface: gr.update(visible=False),
304
  completion_section: gr.update(visible=False),
305
  id_message: gr.update(value="The study is full. Thank you for your interest.", visible=True)
306
  }
 
313
  state.selected_indices = assignments[assignment_key]
314
  data = load_latest_data(prolific_id)
315
  if data:
316
+ if not state.forms_completed:
317
  return {
318
  id_section: gr.update(visible=False),
319
+ forms_section: gr.update(visible=True),
320
  main_interface: gr.update(visible=False),
321
+ completion_section: gr.update(visible=False),
 
322
  id_message: gr.update(value="", visible=False)
323
  }
324
+ elif state.current_idx < 28:
325
  return {
326
  id_section: gr.update(visible=False),
327
+ forms_section: gr.update(visible=False),
328
+ main_interface: gr.update(visible=True),
329
  completion_section: gr.update(visible=False),
330
+ id_message: gr.update(value="", visible=False),
331
+ **update_interface(state.current_idx)
332
  }
333
  else:
334
  return {
335
  id_section: gr.update(visible=False),
 
336
  forms_section: gr.update(visible=False),
337
+ main_interface: gr.update(visible=False),
338
+ completion_section: gr.update(visible=True),
339
+ id_message: gr.update(value="", visible=False)
340
  }
341
  else:
342
  state.annotations = [None] * 28
343
  state.current_idx = 0
344
+ state.forms_completed = False
345
+ state.form_responses = {}
346
  return {
347
  id_section: gr.update(visible=False),
348
+ forms_section: gr.update(visible=True),
349
+ main_interface: gr.update(visible=False),
350
  completion_section: gr.update(visible=False),
351
+ id_message: gr.update(value="", visible=False)
 
352
  }
 
353
  # Updated update_interface to use selected_indices
354
  def update_interface(current_idx):
355
  if current_idx >= 28:
356
+ current_idx = 27
357
  actual_idx = state.selected_indices[current_idx]
358
  current_data = response_pairs[actual_idx]
359
  progress = f"**Progress:** {current_idx/28:.0%} ({min(current_idx, 28)}/28)"
 
380
  gr.Warning(error_msg)
381
  return {
382
  main_interface: gr.update(visible=True),
 
383
  completion_section: gr.update(visible=False),
384
  **update_interface(state.current_idx)
385
  }
 
403
  if new_idx >= 28:
404
  return {
405
  main_interface: gr.update(visible=False),
406
+ completion_section: gr.update(visible=True),
407
+ **update_interface(27)
 
408
  }
409
  else:
410
  return {
411
  main_interface: gr.update(visible=True),
 
412
  completion_section: gr.update(visible=False),
413
  **update_interface(new_idx)
414
  }
 
427
  # New function to handle form submission
428
  def handle_forms_submit(*form_inputs):
429
  if any(input_val is None for input_val in form_inputs):
430
+ gr.Warning("Please answer all questions before proceeding.")
431
  return {
432
  forms_section: gr.update(visible=True),
433
+ main_interface: gr.update(visible=False),
434
  completion_section: gr.update(visible=False)
435
  }
436
  state.form_responses = {}
437
  idx = 0
438
  for form_name, questions in forms_questions.items():
439
  for q in questions:
440
+ key = f"{form_name}_{q['question']}"
441
  state.form_responses[key] = form_inputs[idx]
442
  idx += 1
443
  state.forms_completed = True
444
  save_annotations()
445
+ state.current_idx = 0
446
  return {
447
  forms_section: gr.update(visible=False),
448
+ main_interface: gr.update(visible=True),
449
+ completion_section: gr.update(visible=False),
450
+ **update_interface(0)
451
  }
452
 
453
  # Event bindings
454
  id_submit_btn.click(
455
  handle_id_submit,
456
  inputs=prolific_id,
457
+ outputs=[id_section, forms_section, main_interface, completion_section, id_message, prompt_box,
458
  response_a, response_b, progress_md, feedback, confidence, selection_radio]
459
  )
460
 
461
  prev_btn.click(
462
  handle_navigation,
463
  inputs=[gr.State("prev"), selection_radio, confidence, feedback],
464
+ outputs=[main_interface, completion_section, prompt_box, response_a,
465
  response_b, progress_md, feedback, confidence, selection_radio]
466
  )
467
 
468
  next_btn.click(
469
  handle_navigation,
470
  inputs=[gr.State("next"), selection_radio, confidence, feedback],
471
+ outputs=[main_interface, completion_section, prompt_box, response_a,
472
  response_b, progress_md, feedback, confidence, selection_radio]
473
  )
474
 
 
482
  submit_forms_btn.click(
483
  handle_forms_submit,
484
  inputs=form_radios,
485
+ outputs=[forms_section, main_interface, completion_section, prompt_box, response_a,
486
+ response_b, progress_md, feedback, confidence, selection_radio]
487
  )
488
 
489
  return demo