trydrama-neuralgarage commited on
Commit
aad161c
·
verified ·
1 Parent(s): 54a6c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1028,14 +1028,14 @@ FAQ = [ # order follows the review: what it is, free access, how to, API, then
1028
  ]
1029
 
1030
  # ---------- example grid ("Compare facial expression edits") ----------
1031
- # Clips live in the model repo under drama_examples/<n>/:
1032
  # <n>_original.<ext> the untouched clip
1033
  # <n>_<expression>[_<intensity>].<ext> a DRAMA output, e.g. 2_happy_0.6.mp4 or 6_sad.mp4
1034
  # They are copied into the Space at startup (needs HF_TOKEN with read access while the repo is private),
1035
  # remuxed to MP4 with the index at the front (no re-encoding, so quality is unchanged), and given a
1036
  # still frame, so the page only downloads a clip when someone presses play.
1037
  EXAMPLES_REPO = os.environ.get("EXAMPLES_REPO", "trydrama-neuralgarage/DRAMA")
1038
- EXAMPLES_FOLDER = "drama_examples"
1039
  EXAMPLES_VISIBLE = 3 # rows shown before "Show more examples"
1040
  EX_DOWNLOAD = os.path.abspath("example_cache") # copy of the repo folder
1041
  EX_WEB = os.path.abspath("example_web") # browser-ready MP4s and still frames
@@ -1076,15 +1076,20 @@ def _web_ready(src, n):
1076
 
1077
  def load_examples():
1078
  """Returns [(number, [(label, intensity, video_path, poster_path), ...]), ...]."""
1079
- base = os.path.abspath(EXAMPLES_FOLDER) # a copy uploaded into the Space itself wins
1080
- if not os.path.isdir(base):
 
1081
  try:
1082
  from huggingface_hub import snapshot_download
1083
  snapshot_download(EXAMPLES_REPO, repo_type="model", token=HF_TOKEN or None, local_dir=EX_DOWNLOAD,
1084
- allow_patterns=[f"{EXAMPLES_FOLDER}/*/*"])
1085
- base = os.path.join(EX_DOWNLOAD, EXAMPLES_FOLDER)
 
 
 
 
1086
  except Exception as e:
1087
- log.warning(f"[examples] couldn't copy {EXAMPLES_FOLDER}/ from {EXAMPLES_REPO} "
1088
  f"({type(e).__name__}: {short(str(e), 200)}). HF_TOKEN needs read access to that repo.")
1089
  return []
1090
  rows = []
@@ -1852,5 +1857,5 @@ def favicon_file():
1852
 
1853
  startup_check()
1854
  demo.queue(max_size=20).launch(theme=THEME, css=CSS, js=FORCE_DARK, head=HEAD,
1855
- allowed_paths=[EX_WEB, EX_DOWNLOAD, os.path.abspath(EXAMPLES_FOLDER)],
1856
  favicon_path=favicon_file(), footer_links=[])
 
1028
  ]
1029
 
1030
  # ---------- example grid ("Compare facial expression edits") ----------
1031
+ # Clips live in the model repo under drama-examples/<n>/ (drama_examples/ also works):
1032
  # <n>_original.<ext> the untouched clip
1033
  # <n>_<expression>[_<intensity>].<ext> a DRAMA output, e.g. 2_happy_0.6.mp4 or 6_sad.mp4
1034
  # They are copied into the Space at startup (needs HF_TOKEN with read access while the repo is private),
1035
  # remuxed to MP4 with the index at the front (no re-encoding, so quality is unchanged), and given a
1036
  # still frame, so the page only downloads a clip when someone presses play.
1037
  EXAMPLES_REPO = os.environ.get("EXAMPLES_REPO", "trydrama-neuralgarage/DRAMA")
1038
+ EXAMPLES_FOLDERS = ["drama-examples", "drama_examples"] # either spelling works
1039
  EXAMPLES_VISIBLE = 3 # rows shown before "Show more examples"
1040
  EX_DOWNLOAD = os.path.abspath("example_cache") # copy of the repo folder
1041
  EX_WEB = os.path.abspath("example_web") # browser-ready MP4s and still frames
 
1076
 
1077
  def load_examples():
1078
  """Returns [(number, [(label, intensity, video_path, poster_path), ...]), ...]."""
1079
+ # a copy uploaded into the Space itself wins; otherwise copy it from the model repo
1080
+ base = next((os.path.abspath(f) for f in EXAMPLES_FOLDERS if os.path.isdir(f)), None)
1081
+ if base is None:
1082
  try:
1083
  from huggingface_hub import snapshot_download
1084
  snapshot_download(EXAMPLES_REPO, repo_type="model", token=HF_TOKEN or None, local_dir=EX_DOWNLOAD,
1085
+ allow_patterns=[f"{f}/*/*" for f in EXAMPLES_FOLDERS])
1086
+ base = next((os.path.join(EX_DOWNLOAD, f) for f in EXAMPLES_FOLDERS
1087
+ if os.path.isdir(os.path.join(EX_DOWNLOAD, f))), "")
1088
+ if not base:
1089
+ log.warning(f"[examples] no drama-examples/ folder found in {EXAMPLES_REPO}")
1090
+ return []
1091
  except Exception as e:
1092
+ log.warning(f"[examples] couldn't copy drama-examples/ from {EXAMPLES_REPO} "
1093
  f"({type(e).__name__}: {short(str(e), 200)}). HF_TOKEN needs read access to that repo.")
1094
  return []
1095
  rows = []
 
1857
 
1858
  startup_check()
1859
  demo.queue(max_size=20).launch(theme=THEME, css=CSS, js=FORCE_DARK, head=HEAD,
1860
+ allowed_paths=[EX_WEB, EX_DOWNLOAD, *(os.path.abspath(f) for f in EXAMPLES_FOLDERS)],
1861
  favicon_path=favicon_file(), footer_links=[])