Youngsun Lim commited on
Commit
878203f
ยท
1 Parent(s): ba6d25d
Files changed (1) hide show
  1. app.py +33 -10
app.py CHANGED
@@ -29,14 +29,22 @@ INSTRUCTION_MD = """
29
 
30
  # -------------------- Helper funcs --------------------
31
  def _start_and_load_first():
 
32
  order = random.sample(range(len(V)), k=min(TOTAL_PER_PARTICIPANT, len(V)))
33
  first_idx = order[0]
34
- url, action = V[first_idx]["url"], _extract_action(V[first_idx])
 
35
  return (
36
- gr.update(visible=False),
37
- gr.update(visible=True),
38
- url, action, 5.0, "", 0, _progress_html(0, TOTAL_PER_PARTICIPANT),
39
- order, 1 # order_state, ptr_state ์ดˆ๊ธฐํ™”
 
 
 
 
 
 
40
  )
41
 
42
  start_btn.click(
@@ -299,25 +307,40 @@ with gr.Blocks(fill_height=True, css=GLOBAL_CSS) as demo:
299
  )
300
 
301
  # -------- Save & Next (๋…ธํŠธ ์—†์Œ) --------
302
- def save_and_next(participant_id, action_name, score_val, done_cnt):
303
  if not participant_id or not participant_id.strip():
 
304
  return (
305
  gr.update(visible=True, value="โ— Please enter your Participant ID."),
306
- gr.update(), gr.update(), # video, action_tb (๋ณ€๊ฒฝ ์—†์Œ)
307
  done_cnt,
308
  _progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
309
- 5.0 # score reset ์œ ์ง€
 
310
  )
 
311
  status_msg = push(participant_id, action_name, score_val, "")
312
 
313
  new_done = int(done_cnt) + 1
 
314
  if new_done >= TOTAL_PER_PARTICIPANT or ptr >= len(order):
315
- return (... ์ข…๋ฃŒ UI ... , ptr)
 
 
 
 
 
 
 
 
 
 
316
  next_idx = order[ptr]
317
  v = V[next_idx]
318
  return (
319
  status_msg,
320
- v["url"], _extract_action(v),
 
321
  new_done,
322
  _progress_html(new_done, TOTAL_PER_PARTICIPANT),
323
  5.0,
 
29
 
30
  # -------------------- Helper funcs --------------------
31
  def _start_and_load_first():
32
+ # ํ‰๊ฐ€ํ•  ์ธ๋ฑ์Šค ์ˆœ์„œ (์…”ํ”Œ)
33
  order = random.sample(range(len(V)), k=min(TOTAL_PER_PARTICIPANT, len(V)))
34
  first_idx = order[0]
35
+ v0 = V[first_idx]
36
+ url0, action0 = v0["url"], _extract_action(v0)
37
  return (
38
+ gr.update(visible=False), # page_intro off
39
+ gr.update(visible=True), # page_eval on
40
+ url0, # video
41
+ action0, # action_tb
42
+ 5.0, # score ์ดˆ๊ธฐ๊ฐ’
43
+ "", # status (๋นˆ ๋ฉ”์‹œ์ง€)
44
+ 0, # done_state
45
+ _progress_html(0, TOTAL_PER_PARTICIPANT),
46
+ order, # order_state ์ดˆ๊ธฐํ™”
47
+ 1 # ptr_state: ๋‹ค์Œ ์ธ๋ฑ์Šค ํฌ์ธํ„ฐ
48
  )
49
 
50
  start_btn.click(
 
307
  )
308
 
309
  # -------- Save & Next (๋…ธํŠธ ์—†์Œ) --------
310
+ def save_and_next(participant_id, action_name, score_val, done_cnt, order, ptr):
311
  if not participant_id or not participant_id.strip():
312
+ # PID ์—†์œผ๋ฉด ๊ธฐ์กด ํ™”๋ฉด ์œ ์ง€
313
  return (
314
  gr.update(visible=True, value="โ— Please enter your Participant ID."),
315
+ gr.update(), gr.update(), # video, action_tb ๋ณ€๊ฒฝ ์—†์Œ
316
  done_cnt,
317
  _progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
318
+ 5.0,
319
+ ptr
320
  )
321
+
322
  status_msg = push(participant_id, action_name, score_val, "")
323
 
324
  new_done = int(done_cnt) + 1
325
+ # ์ข…๋ฃŒ ์กฐ๊ฑด: ๋ชฉํ‘œ ๊ฐœ์ˆ˜ ๋‹ฌ์„ฑ or ์ˆœ์„œ ์†Œ์ง„
326
  if new_done >= TOTAL_PER_PARTICIPANT or ptr >= len(order):
327
+ return (
328
+ status_msg, # status
329
+ None, # video ๋น„์šฐ๊ธฐ
330
+ "", # action_tb ๋น„์šฐ๊ธฐ
331
+ TOTAL_PER_PARTICIPANT, # done_state ์ตœ์ข…
332
+ _progress_html(TOTAL_PER_PARTICIPANT, TOTAL_PER_PARTICIPANT),
333
+ 5.0, # score ๋ฆฌ์…‹
334
+ ptr # ptr ์œ ์ง€
335
+ )
336
+
337
+ # ๋‹ค์Œ ์˜์ƒ ๋กœ๋“œ
338
  next_idx = order[ptr]
339
  v = V[next_idx]
340
  return (
341
  status_msg,
342
+ v["url"],
343
+ _extract_action(v),
344
  new_done,
345
  _progress_html(new_done, TOTAL_PER_PARTICIPANT),
346
  5.0,