Youngsun Lim commited on
Commit
2d68ea1
ยท
1 Parent(s): 3e7619c

add random code

Browse files
Files changed (1) hide show
  1. app.py +83 -83
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
- 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
 
 
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