Spaces:
Build error
Build error
Youngsun Lim commited on
Commit ยท
878203f
1
Parent(s): ba6d25d
1014
Browse files
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 |
-
|
|
|
|
| 35 |
return (
|
| 36 |
-
gr.update(visible=False),
|
| 37 |
-
gr.update(visible=True),
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(),
|
| 307 |
done_cnt,
|
| 308 |
_progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
|
| 309 |
-
5.0
|
|
|
|
| 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 (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
next_idx = order[ptr]
|
| 317 |
v = V[next_idx]
|
| 318 |
return (
|
| 319 |
status_msg,
|
| 320 |
-
v["url"],
|
|
|
|
| 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,
|