Spaces:
Sleeping
Sleeping
Youngsun Lim
commited on
Commit
·
509b1bc
1
Parent(s):
9c1b594
2nd page fail error
Browse files
app.py
CHANGED
|
@@ -8,6 +8,43 @@ import subprocess, pathlib, hashlib
|
|
| 8 |
import secrets, time, string
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# 사용자가 '선택'을 완료한 값 (초기엔 None)
|
| 12 |
selected_action = gr.State(None)
|
| 13 |
selected_phys = gr.State(None)
|
|
@@ -874,6 +911,37 @@ with gr.Blocks(css=CLEAN_BG_CSS) as demo:
|
|
| 874 |
|
| 875 |
return seq
|
| 876 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 877 |
def _start_and_load_first():
|
| 878 |
total = TOTAL_PER_PARTICIPANT
|
| 879 |
order = _build_order_least_first_with_anchor(
|
|
@@ -884,25 +952,27 @@ with gr.Blocks(css=CLEAN_BG_CSS) as demo:
|
|
| 884 |
)
|
| 885 |
first_idx = order[0]
|
| 886 |
v0 = V[first_idx]
|
|
|
|
|
|
|
|
|
|
| 887 |
return (
|
| 888 |
gr.update(visible=False),
|
| 889 |
gr.update(visible=True),
|
| 890 |
gr.update(visible=False),
|
| 891 |
-
v0["url"]
|
| 892 |
_extract_action(v0),
|
| 893 |
-
5.0,
|
| 894 |
-
5.0,
|
| 895 |
gr.update(visible=False, value=""),
|
| 896 |
0,
|
| 897 |
_progress_html(0, TOTAL_PER_PARTICIPANT),
|
| 898 |
order,
|
| 899 |
1,
|
| 900 |
-
_get_video_id(v0),
|
| 901 |
"",
|
| 902 |
-
None,
|
| 903 |
-
None,
|
| 904 |
-
|
| 905 |
-
gr.update(interactive=False, variant="secondary"), # ⬅️ Save 버튼 잠금
|
| 906 |
)
|
| 907 |
|
| 908 |
|
|
@@ -989,10 +1059,14 @@ with gr.Blocks(css=CLEAN_BG_CSS) as demo:
|
|
| 989 |
v = V[next_idx]
|
| 990 |
next_vid = _get_video_id(v)
|
| 991 |
|
|
|
|
|
|
|
|
|
|
| 992 |
return (
|
| 993 |
gr.update(visible=True),
|
| 994 |
gr.update(visible=False),
|
| 995 |
status_msg,
|
|
|
|
| 996 |
v["url"],
|
| 997 |
_extract_action(v),
|
| 998 |
new_done,
|
|
|
|
| 8 |
import secrets, time, string
|
| 9 |
|
| 10 |
|
| 11 |
+
from functools import lru_cache
|
| 12 |
+
|
| 13 |
+
@lru_cache(maxsize=2048)
|
| 14 |
+
def get_local_video_path(hf_url_or_relpath: str) -> str:
|
| 15 |
+
"""
|
| 16 |
+
hf_url_or_relpath:
|
| 17 |
+
- 만약 이미 로컬 경로(/tmp/...mp4 등)이면 그대로 리턴
|
| 18 |
+
- 만약 'videos/...mp4' 같은 repo 내부 경로면 hf_hub_download로 받아서 로컬 경로 리턴
|
| 19 |
+
- 만약 https://huggingface.co/... 형태면 파일명만 떼와서 받아서 로컬 리턴
|
| 20 |
+
"""
|
| 21 |
+
# 1) 이미 로컬 파일이면 그대로
|
| 22 |
+
if os.path.exists(hf_url_or_relpath):
|
| 23 |
+
return ensure_muted_copy(hf_url_or_relpath)
|
| 24 |
+
|
| 25 |
+
# 2) 허깅페이스 프라이빗 URL일 가능성 -> 파일 basename 뽑기
|
| 26 |
+
basename = os.path.basename(hf_url_or_relpath)
|
| 27 |
+
|
| 28 |
+
# 우리가 실제 dataset repo에 올려둔 mp4가 예를 들면 "videos/Wan2.2_...mp4" 이런 구조라고 가정
|
| 29 |
+
# videos.json이 url 대신 repo 내부 상대경로를 담도록 되어 있으면 제일 깔끔함.
|
| 30 |
+
# 만약 진짜로 "videos/....mp4" 이런 상대경로를 가지고 있다면 그대로 쓰고:
|
| 31 |
+
possible_rel = hf_url_or_relpath
|
| 32 |
+
# 혹시 전체 URL이었다면 basename만 쓰는 식으로 단순화:
|
| 33 |
+
if possible_rel.startswith("http"):
|
| 34 |
+
possible_rel = f"videos/{basename}"
|
| 35 |
+
|
| 36 |
+
local_path = hf_hub_download(
|
| 37 |
+
repo_id=REPO_ID,
|
| 38 |
+
filename=possible_rel,
|
| 39 |
+
repo_type="dataset",
|
| 40 |
+
token=HF_TOKEN,
|
| 41 |
+
local_dir="/tmp",
|
| 42 |
+
local_dir_use_symlinks=False,
|
| 43 |
+
)
|
| 44 |
+
# 음소거본까지 만들기(네가 이미 ensure_muted_copy() 준비해둠)
|
| 45 |
+
return ensure_muted_copy(local_path)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
# 사용자가 '선택'을 완료한 값 (초기엔 None)
|
| 49 |
selected_action = gr.State(None)
|
| 50 |
selected_phys = gr.State(None)
|
|
|
|
| 911 |
|
| 912 |
return seq
|
| 913 |
|
| 914 |
+
# def _start_and_load_first():
|
| 915 |
+
# total = TOTAL_PER_PARTICIPANT
|
| 916 |
+
# order = _build_order_least_first_with_anchor(
|
| 917 |
+
# total=total,
|
| 918 |
+
# anchor_idx=ANCHOR_IDX,
|
| 919 |
+
# repeats=ANCHOR_REPEATS,
|
| 920 |
+
# min_gap=MIN_GAP
|
| 921 |
+
# )
|
| 922 |
+
# first_idx = order[0]
|
| 923 |
+
# v0 = V[first_idx]
|
| 924 |
+
# return (
|
| 925 |
+
# gr.update(visible=False),
|
| 926 |
+
# gr.update(visible=True),
|
| 927 |
+
# gr.update(visible=False),
|
| 928 |
+
# v0["url"],
|
| 929 |
+
# _extract_action(v0),
|
| 930 |
+
# 5.0, # score_action default
|
| 931 |
+
# 5.0, # score_phys default ✅ NEW
|
| 932 |
+
# gr.update(visible=False, value=""),
|
| 933 |
+
# 0,
|
| 934 |
+
# _progress_html(0, TOTAL_PER_PARTICIPANT),
|
| 935 |
+
# order,
|
| 936 |
+
# 1,
|
| 937 |
+
# _get_video_id(v0), # cur_video_id
|
| 938 |
+
# "",
|
| 939 |
+
# None, # ⬅️ selected_action 초기화(= 아직 선택 안됨)
|
| 940 |
+
# None, # ⬅️ selected_phys 초기화
|
| 941 |
+
|
| 942 |
+
# gr.update(interactive=False, variant="secondary"), # ⬅️ Save 버튼 잠금
|
| 943 |
+
# )
|
| 944 |
+
|
| 945 |
def _start_and_load_first():
|
| 946 |
total = TOTAL_PER_PARTICIPANT
|
| 947 |
order = _build_order_least_first_with_anchor(
|
|
|
|
| 952 |
)
|
| 953 |
first_idx = order[0]
|
| 954 |
v0 = V[first_idx]
|
| 955 |
+
|
| 956 |
+
local_vid_path = get_local_video_path(v0["url"]) # <= 여기서 로컬 경로 확보
|
| 957 |
+
|
| 958 |
return (
|
| 959 |
gr.update(visible=False),
|
| 960 |
gr.update(visible=True),
|
| 961 |
gr.update(visible=False),
|
| 962 |
+
local_vid_path, # <- v0["url"] 대신 로컬 경로
|
| 963 |
_extract_action(v0),
|
| 964 |
+
5.0,
|
| 965 |
+
5.0,
|
| 966 |
gr.update(visible=False, value=""),
|
| 967 |
0,
|
| 968 |
_progress_html(0, TOTAL_PER_PARTICIPANT),
|
| 969 |
order,
|
| 970 |
1,
|
| 971 |
+
_get_video_id(v0),
|
| 972 |
"",
|
| 973 |
+
None,
|
| 974 |
+
None,
|
| 975 |
+
gr.update(interactive=False, variant="secondary"),
|
|
|
|
| 976 |
)
|
| 977 |
|
| 978 |
|
|
|
|
| 1059 |
v = V[next_idx]
|
| 1060 |
next_vid = _get_video_id(v)
|
| 1061 |
|
| 1062 |
+
local_vid_path = get_local_video_path(v["url"]) # 새 비디오 로컬 경로
|
| 1063 |
+
|
| 1064 |
+
|
| 1065 |
return (
|
| 1066 |
gr.update(visible=True),
|
| 1067 |
gr.update(visible=False),
|
| 1068 |
status_msg,
|
| 1069 |
+
local_vid_path,
|
| 1070 |
v["url"],
|
| 1071 |
_extract_action(v),
|
| 1072 |
new_done,
|