Spaces:
Sleeping
Sleeping
Youngsun Lim
commited on
Commit
ยท
2d68ea1
1
Parent(s):
3e7619c
add random code
Browse files
app.py
CHANGED
|
@@ -856,97 +856,97 @@ with gr.Blocks() as demo: #css=GLOBAL_CSS
|
|
| 856 |
# cur_vid
|
| 857 |
# )
|
| 858 |
|
| 859 |
-
def save_and_next(participant_id, cur_vid, score_val, done_cnt, order, ptr, reward_code):
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 863 |
return (
|
| 864 |
-
gr.update(visible=True),
|
| 865 |
-
gr.update(visible=False),
|
| 866 |
-
gr.update(visible=True, value="
|
| 867 |
gr.update(), gr.update(),
|
| 868 |
done_cnt,
|
| 869 |
_progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
|
| 870 |
5.0,
|
| 871 |
ptr,
|
| 872 |
cur_vid,
|
| 873 |
-
reward_code,
|
| 874 |
-
gr.update(visible=False),
|
| 875 |
-
gr.update(visible=False)
|
| 876 |
-
)
|
| 877 |
-
|
| 878 |
-
# ์ ์ฅ
|
| 879 |
-
status_msg = push(participant_id, cur_vid, score_val, "")
|
| 880 |
-
new_done = int(done_cnt) + 1
|
| 881 |
-
|
| 882 |
-
# ์๋ฃ ์กฐ๊ฑด
|
| 883 |
-
if new_done >= TOTAL_PER_PARTICIPANT or ptr >= len(order):
|
| 884 |
-
# ์ด๋ฏธ ์ฝ๋๊ฐ ์์ผ๋ฉด ์ฌ์ฌ์ฉ(์ค๋ณต ์์ฑ ๋ฐฉ์ง)
|
| 885 |
-
code = reward_code.strip() or _gen_reward_code(participant_id, length=10)
|
| 886 |
-
# ์ฝ๋ ๊ธฐ๋ก(HF)
|
| 887 |
-
try:
|
| 888 |
-
_persist_reward_code(participant_id, code, new_done)
|
| 889 |
-
except Exception as e:
|
| 890 |
-
# ๊ธฐ๋ก ์คํจํด๋ ํ๋ฉด์ ์ฝ๋๋ ๋ณด์ฌ์ค
|
| 891 |
-
pass
|
| 892 |
-
|
| 893 |
-
# ๊ณ ์ ๋ฉ์์ง + ์ฝ๋ ๋ฐ์ค ๋
ธ์ถ
|
| 894 |
-
thanks_text = (
|
| 895 |
-
"## ๐ Thank you so much!\n"
|
| 896 |
-
"Your responses have been recorded.\n\n"
|
| 897 |
-
"**Below is your reward code.** Please copy and submit it to receive your payment."
|
| 898 |
)
|
| 899 |
-
return (
|
| 900 |
-
gr.update(visible=False), # page_eval ์จ๊น
|
| 901 |
-
gr.update(visible=True), # thanks ๋ณด์
|
| 902 |
-
status_msg,
|
| 903 |
-
None, # video ๋น์ฐ๊ธฐ
|
| 904 |
-
"", # action_tb ๋น์ฐ๊ธฐ
|
| 905 |
-
TOTAL_PER_PARTICIPANT,
|
| 906 |
-
_progress_html(TOTAL_PER_PARTICIPANT, TOTAL_PER_PARTICIPANT),
|
| 907 |
-
5.0,
|
| 908 |
-
len(order),
|
| 909 |
-
cur_vid,
|
| 910 |
-
code, # โ
reward_code_state ๊ฐฑ์
|
| 911 |
-
gr.update(visible=True, value=thanks_text), # reward_msg
|
| 912 |
-
gr.update(visible=True, value=code) # reward_code_box
|
| 913 |
-
)
|
| 914 |
-
|
| 915 |
-
# ๋ค์ ์์
|
| 916 |
-
next_idx = order[ptr]
|
| 917 |
-
v = V[next_idx]
|
| 918 |
-
next_vid = _get_video_id(v)
|
| 919 |
-
|
| 920 |
-
return (
|
| 921 |
-
gr.update(visible=True), # page_eval ์ ์ง
|
| 922 |
-
gr.update(visible=False), # thanks ์จ๊น
|
| 923 |
-
status_msg,
|
| 924 |
-
v["url"],
|
| 925 |
-
_extract_action(v),
|
| 926 |
-
new_done,
|
| 927 |
-
_progress_html(new_done, TOTAL_PER_PARTICIPANT),
|
| 928 |
-
5.0,
|
| 929 |
-
ptr + 1,
|
| 930 |
-
next_vid,
|
| 931 |
-
reward_code, # ๊ทธ๋๋ก ์ ์ง
|
| 932 |
-
gr.update(visible=False), # reward_msg ์จ๊น
|
| 933 |
-
gr.update(visible=False) # reward_code_box ์จ๊น
|
| 934 |
-
)
|
| 935 |
-
except Exception as e:
|
| 936 |
-
return (
|
| 937 |
-
gr.update(visible=True),
|
| 938 |
-
gr.update(visible=False),
|
| 939 |
-
gr.update(visible=True, value=f"โ Error: {type(e).__name__}: {e}"),
|
| 940 |
-
gr.update(), gr.update(),
|
| 941 |
-
done_cnt,
|
| 942 |
-
_progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
|
| 943 |
-
5.0,
|
| 944 |
-
ptr,
|
| 945 |
-
cur_vid,
|
| 946 |
-
reward_code,
|
| 947 |
-
gr.update(visible=False),
|
| 948 |
-
gr.update(visible=False)
|
| 949 |
-
)
|
| 950 |
|
| 951 |
|
| 952 |
|
|
|
|
| 856 |
# cur_vid
|
| 857 |
# )
|
| 858 |
|
| 859 |
+
def save_and_next(participant_id, cur_vid, score_val, done_cnt, order, ptr, reward_code):
|
| 860 |
+
try:
|
| 861 |
+
# PID ์์ผ๋ฉด ํ๋ฉด ์ ์ง
|
| 862 |
+
if not participant_id or not participant_id.strip():
|
| 863 |
+
return (
|
| 864 |
+
gr.update(visible=True), # page_eval ์ ์ง
|
| 865 |
+
gr.update(visible=False), # thanks ์จ๊น
|
| 866 |
+
gr.update(visible=True, value="โ Please enter your Participant ID."),
|
| 867 |
+
gr.update(), gr.update(),
|
| 868 |
+
done_cnt,
|
| 869 |
+
_progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
|
| 870 |
+
5.0,
|
| 871 |
+
ptr,
|
| 872 |
+
cur_vid,
|
| 873 |
+
reward_code, # pass through
|
| 874 |
+
gr.update(visible=False), # reward_msg
|
| 875 |
+
gr.update(visible=False) # reward_code_box
|
| 876 |
+
)
|
| 877 |
+
|
| 878 |
+
# ์ ์ฅ
|
| 879 |
+
status_msg = push(participant_id, cur_vid, score_val, "")
|
| 880 |
+
new_done = int(done_cnt) + 1
|
| 881 |
+
|
| 882 |
+
# ์๋ฃ ์กฐ๊ฑด
|
| 883 |
+
if new_done >= TOTAL_PER_PARTICIPANT or ptr >= len(order):
|
| 884 |
+
# ์ด๋ฏธ ์ฝ๋๊ฐ ์์ผ๋ฉด ์ฌ์ฌ์ฉ(์ค๋ณต ์์ฑ ๋ฐฉ์ง)
|
| 885 |
+
code = reward_code.strip() or _gen_reward_code(participant_id, length=10)
|
| 886 |
+
# ์ฝ๋ ๊ธฐ๋ก(HF)
|
| 887 |
+
try:
|
| 888 |
+
_persist_reward_code(participant_id, code, new_done)
|
| 889 |
+
except Exception as e:
|
| 890 |
+
# ๊ธฐ๋ก ์คํจํด๋ ํ๋ฉด์ ์ฝ๋๋ ๋ณด์ฌ์ค
|
| 891 |
+
pass
|
| 892 |
+
|
| 893 |
+
# ๊ณ ์ ๋ฉ์์ง + ์ฝ๋ ๋ฐ์ค ๋
ธ์ถ
|
| 894 |
+
thanks_text = (
|
| 895 |
+
"## ๐ Thank you so much!\n"
|
| 896 |
+
"Your responses have been recorded.\n\n"
|
| 897 |
+
"**Below is your reward code.** Please copy and submit it to receive your payment."
|
| 898 |
+
)
|
| 899 |
+
return (
|
| 900 |
+
gr.update(visible=False), # page_eval ์จ๊น
|
| 901 |
+
gr.update(visible=True), # thanks ๋ณด์
|
| 902 |
+
status_msg,
|
| 903 |
+
None, # video ๋น์ฐ๊ธฐ
|
| 904 |
+
"", # action_tb ๋น์ฐ๊ธฐ
|
| 905 |
+
TOTAL_PER_PARTICIPANT,
|
| 906 |
+
_progress_html(TOTAL_PER_PARTICIPANT, TOTAL_PER_PARTICIPANT),
|
| 907 |
+
5.0,
|
| 908 |
+
len(order),
|
| 909 |
+
cur_vid,
|
| 910 |
+
code, # โ
reward_code_state ๊ฐฑ์
|
| 911 |
+
gr.update(visible=True, value=thanks_text), # reward_msg
|
| 912 |
+
gr.update(visible=True, value=code) # reward_code_box
|
| 913 |
+
)
|
| 914 |
+
|
| 915 |
+
# ๋ค์ ์์
|
| 916 |
+
next_idx = order[ptr]
|
| 917 |
+
v = V[next_idx]
|
| 918 |
+
next_vid = _get_video_id(v)
|
| 919 |
+
|
| 920 |
+
return (
|
| 921 |
+
gr.update(visible=True), # page_eval ์ ์ง
|
| 922 |
+
gr.update(visible=False), # thanks ์จ๊น
|
| 923 |
+
status_msg,
|
| 924 |
+
v["url"],
|
| 925 |
+
_extract_action(v),
|
| 926 |
+
new_done,
|
| 927 |
+
_progress_html(new_done, TOTAL_PER_PARTICIPANT),
|
| 928 |
+
5.0,
|
| 929 |
+
ptr + 1,
|
| 930 |
+
next_vid,
|
| 931 |
+
reward_code, # ๊ทธ๋๋ก ์ ์ง
|
| 932 |
+
gr.update(visible=False), # reward_msg ์จ๊น
|
| 933 |
+
gr.update(visible=False) # reward_code_box ์จ๊น
|
| 934 |
+
)
|
| 935 |
+
except Exception as e:
|
| 936 |
return (
|
| 937 |
+
gr.update(visible=True),
|
| 938 |
+
gr.update(visible=False),
|
| 939 |
+
gr.update(visible=True, value=f"โ Error: {type(e).__name__}: {e}"),
|
| 940 |
gr.update(), gr.update(),
|
| 941 |
done_cnt,
|
| 942 |
_progress_html(done_cnt, TOTAL_PER_PARTICIPANT),
|
| 943 |
5.0,
|
| 944 |
ptr,
|
| 945 |
cur_vid,
|
| 946 |
+
reward_code,
|
| 947 |
+
gr.update(visible=False),
|
| 948 |
+
gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 950 |
|
| 951 |
|
| 952 |
|