Spaces:
Sleeping
Sleeping
Youngsun Lim commited on
Commit ยท
ae854f2
1
Parent(s): 509b1bc
2nd page fail error
Browse files
app.py
CHANGED
|
@@ -10,41 +10,63 @@ import secrets, time, string
|
|
| 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 |
-
|
| 17 |
-
|
| 18 |
-
- ๋ง์ฝ 'videos/...mp4' ๊ฐ์ repo ๋ด๋ถ ๊ฒฝ๋ก๋ฉด hf_hub_download๋ก ๋ฐ์์ ๋ก์ปฌ ๊ฒฝ๋ก ๋ฆฌํด
|
| 19 |
-
- ๋ง์ฝ https://huggingface.co/... ํํ๋ฉด ํ์ผ๋ช
๋ง ๋ผ์์ ๋ฐ์์ ๋ก์ปฌ ๋ฆฌํด
|
| 20 |
"""
|
| 21 |
-
#
|
| 22 |
if os.path.exists(hf_url_or_relpath):
|
| 23 |
return ensure_muted_copy(hf_url_or_relpath)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
# ์ฐ๋ฆฌ๊ฐ
|
| 29 |
-
|
| 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=
|
| 39 |
-
repo_type=
|
| 40 |
token=HF_TOKEN,
|
| 41 |
local_dir="/tmp",
|
| 42 |
local_dir_use_symlinks=False,
|
| 43 |
)
|
| 44 |
-
|
|
|
|
| 45 |
return ensure_muted_copy(local_path)
|
| 46 |
|
| 47 |
|
|
|
|
| 48 |
# ์ฌ์ฉ์๊ฐ '์ ํ'์ ์๋ฃํ ๊ฐ (์ด๊ธฐ์ None)
|
| 49 |
selected_action = gr.State(None)
|
| 50 |
selected_phys = gr.State(None)
|
|
@@ -191,7 +213,9 @@ def push_final_feedback(participant_id: str, comment: str):
|
|
| 191 |
|
| 192 |
|
| 193 |
# -------------------- Config --------------------
|
| 194 |
-
REPO_ID = os.getenv("RESULTS_REPO", "dghadiya/video_eval") # ์
๋ก๋ํ ๋ฆฌํฌ์ ์ผ์น
|
|
|
|
|
|
|
| 195 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 196 |
RESULTS_FILE = "results.csv"
|
| 197 |
TOTAL_PER_PARTICIPANT = 30 # ๋ชฉํ ํ๊ฐ ๊ฐ์(์ธ์
๊ธฐ์ค)
|
|
|
|
| 10 |
|
| 11 |
from functools import lru_cache
|
| 12 |
|
| 13 |
+
def _infer_relpath_from_filename(url_or_name: str) -> str:
|
| 14 |
+
"""
|
| 15 |
+
url_or_name: videos.json์ ๋ค์ด์๋ v["url"] (์ ์ฒด URL์ด๋ ํ์ผ๋ช
๋ง์ด๋ )
|
| 16 |
+
return: HF dataset ๋ด๋ถ์์์ ์๋๊ฒฝ๋ก
|
| 17 |
+
ex) "video_examples/Wan2.2/Wan2.2/Wan2.2_BodyWeightSquats_01_g01_c01.mp4"
|
| 18 |
+
๊ท์น:
|
| 19 |
+
1) basename๋ง ๋ฝ๋๋ค.
|
| 20 |
+
2) prefix = basename.split('_')[0] (์: "Wan2.2", "Hunyuan_videos", "wan21_videos", "RunwayGen4")
|
| 21 |
+
3) relpath = f"video_examples/{prefix}/{prefix}/{basename}"
|
| 22 |
+
"""
|
| 23 |
+
# 1) ํน์ ์ ์ฒด URL์ด๋ฉด ๋งจ ๋ง์ง๋ง ํ์ผ๋ช
๋ง ์ถ์ถ
|
| 24 |
+
base = os.path.basename(url_or_name)
|
| 25 |
+
|
| 26 |
+
# 2) prefix ๋ ์ฒซ '_' ์ด์ ๊น์ง
|
| 27 |
+
# ์: "Wan2.2_BodyWeightSquats_01_g01_c01.mp4" -> "Wan2.2"
|
| 28 |
+
# "Hunyuan_videos_BodyWeightSquats_01_08d40ea1.mp4" -> "Hunyuan_videos"
|
| 29 |
+
# ๋ง์ฝ '_'๊ฐ ์๋ค๋ฉด ์ ์ฒด ์ด๋ฆ ์์ฒด๋ฅผ prefix๋ก ์ด๋ค.
|
| 30 |
+
if "_" in base:
|
| 31 |
+
prefix = base.split("_")[0]
|
| 32 |
+
else:
|
| 33 |
+
prefix = os.path.splitext(base)[0]
|
| 34 |
+
|
| 35 |
+
# 3) ์ต์ข
์๋๊ฒฝ๋ก
|
| 36 |
+
rel = f"video_examples/{prefix}/{prefix}/{base}"
|
| 37 |
+
return rel
|
| 38 |
+
|
| 39 |
+
|
| 40 |
@lru_cache(maxsize=2048)
|
| 41 |
def get_local_video_path(hf_url_or_relpath: str) -> str:
|
| 42 |
"""
|
| 43 |
+
1) ์ด๋ฏธ ๋ก์ปฌ์ด๋ฉด ๊ทธ๋๋ก ์ด๋ค.
|
| 44 |
+
2) ์๋๋ฉด repo์์ hf_hub_download๋ก ๋ฐ์์ /tmp์ ์ ์ฅํ๊ณ ์์๊ฑฐ๋ณธ ๊ฒฝ๋ก ๋ฆฌํด.
|
|
|
|
|
|
|
| 45 |
"""
|
| 46 |
+
# ๋ก์ปฌ ๊ฒฝ๋ก๋ฉด ๋ฐ๋ก ์ฌ์ฉ
|
| 47 |
if os.path.exists(hf_url_or_relpath):
|
| 48 |
return ensure_muted_copy(hf_url_or_relpath)
|
| 49 |
|
| 50 |
+
if not HF_TOKEN:
|
| 51 |
+
raise RuntimeError("HF_TOKEN is not set or empty in this Space. Please add it as a secret.")
|
| 52 |
|
| 53 |
+
# ์ฐ๋ฆฌ๊ฐ ๊ฐ์ง ๋ฌธ์์ด๋ก๋ถํฐ HF repo ๋ด๋ถ ๊ฒฝ๋ก๋ฅผ ์ถ๋ก
|
| 54 |
+
rel = _infer_relpath_from_filename(hf_url_or_relpath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
local_path = hf_hub_download(
|
| 57 |
repo_id=REPO_ID,
|
| 58 |
+
filename=rel,
|
| 59 |
+
repo_type=REPO_TYPE,
|
| 60 |
token=HF_TOKEN,
|
| 61 |
local_dir="/tmp",
|
| 62 |
local_dir_use_symlinks=False,
|
| 63 |
)
|
| 64 |
+
|
| 65 |
+
# ๋ฌด์ ๋ฒ์ ์ผ๋ก ๋ณํํด์ ๋ฆฌํด
|
| 66 |
return ensure_muted_copy(local_path)
|
| 67 |
|
| 68 |
|
| 69 |
+
|
| 70 |
# ์ฌ์ฉ์๊ฐ '์ ํ'์ ์๋ฃํ ๊ฐ (์ด๊ธฐ์ None)
|
| 71 |
selected_action = gr.State(None)
|
| 72 |
selected_phys = gr.State(None)
|
|
|
|
| 213 |
|
| 214 |
|
| 215 |
# -------------------- Config --------------------
|
| 216 |
+
# REPO_ID = os.getenv("RESULTS_REPO", "dghadiya/video_eval") # ์
๋ก๋ํ ๋ฆฌํฌ์ ์ผ์น
|
| 217 |
+
REPO_ID = os.getenv("RESULTS_REPO", "dghadiya/video_examples")
|
| 218 |
+
|
| 219 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 220 |
RESULTS_FILE = "results.csv"
|
| 221 |
TOTAL_PER_PARTICIPANT = 30 # ๋ชฉํ ํ๊ฐ ๊ฐ์(์ธ์
๊ธฐ์ค)
|