Youngsun Lim commited on
Commit
ba6d25d
Β·
1 Parent(s): 2923baa
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -8,7 +8,10 @@ from huggingface_hub import HfApi, hf_hub_download
8
  REPO_ID = os.getenv("RESULTS_REPO", "sgtlim/videoeval_results") # μ—…λ‘œλ“œν•œ 리포와 일치
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
  RESULTS_FILE = "results.csv"
11
- TOTAL_PER_PARTICIPANT = 50 # λͺ©ν‘œ 평가 개수(μ„Έμ…˜ κΈ°μ€€)
 
 
 
12
 
13
  # videos.json μ˜ˆμ‹œ: {"url": "...mp4", "id": "BodyWeightSquats__XXXX.mp4", "action": "BodyWeightSquats"}
14
  with open("videos.json", "r", encoding="utf-8") as f:
@@ -25,6 +28,23 @@ INSTRUCTION_MD = """
25
  """
26
 
27
  # -------------------- Helper funcs --------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def _read_csv_bytes():
29
  try:
30
  p = hf_hub_download(
@@ -291,28 +311,23 @@ with gr.Blocks(fill_height=True, css=GLOBAL_CSS) as demo:
291
  status_msg = push(participant_id, action_name, score_val, "")
292
 
293
  new_done = int(done_cnt) + 1
294
- if new_done >= TOTAL_PER_PARTICIPANT:
295
- return (
296
- status_msg,
297
- None, "", # λ§ˆμ§€λ§‰: μƒˆ λΉ„λ””μ˜€ λ‘œλ“œ μ•ˆ 함
298
- TOTAL_PER_PARTICIPANT,
299
- _progress_html(TOTAL_PER_PARTICIPANT, TOTAL_PER_PARTICIPANT),
300
- 5.0
301
- )
302
-
303
- url, next_action = pick_one()
304
  return (
305
  status_msg,
306
- url, next_action,
307
  new_done,
308
  _progress_html(new_done, TOTAL_PER_PARTICIPANT),
309
- 5.0
 
310
  )
311
 
312
  save_next.click(
313
  save_and_next,
314
- inputs=[pid, action_tb, score, done_state],
315
- outputs=[status, video, action_tb, done_state, progress, score]
316
  )
317
 
318
  if __name__ == "__main__":
 
8
  REPO_ID = os.getenv("RESULTS_REPO", "sgtlim/videoeval_results") # μ—…λ‘œλ“œν•œ 리포와 일치
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
  RESULTS_FILE = "results.csv"
11
+ TOTAL_PER_PARTICIPANT = 30 # λͺ©ν‘œ 평가 개수(μ„Έμ…˜ κΈ°μ€€)
12
+
13
+ order_state = gr.State([])
14
+ ptr_state = gr.State(0)
15
 
16
  # videos.json μ˜ˆμ‹œ: {"url": "...mp4", "id": "BodyWeightSquats__XXXX.mp4", "action": "BodyWeightSquats"}
17
  with open("videos.json", "r", encoding="utf-8") as f:
 
28
  """
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(
43
+ _start_and_load_first,
44
+ inputs=[],
45
+ outputs=[page_intro, page_eval, video, action_tb, score, status, done_state, progress, order_state, ptr_state]
46
+ )
47
+
48
  def _read_csv_bytes():
49
  try:
50
  p = hf_hub_download(
 
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,
324
+ ptr + 1
325
  )
326
 
327
  save_next.click(
328
  save_and_next,
329
+ inputs=[pid, action_tb, score, done_state, order_state, ptr_state],
330
+ outputs=[status, video, action_tb, done_state, progress, score, ptr_state]
331
  )
332
 
333
  if __name__ == "__main__":