SMSD75 commited on
Commit
c5a7f41
·
verified ·
1 Parent(s): dca285c

Update SynthScope Space from the GitHub repository

Browse files
deploy/hf-space/build_demo_pack.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Build SynthScope's online-demo data pack: a few files per generator from several openly licensed benchmarks, in the
2
+ layout the web app reads (<Folder>/test/<generator>/{0_real,1_fake} or EvalCrafter's test/1_fake/<generator>), plus a
3
+ README with sources and licenses. Files are picked evenly across each folder (deterministic)."""
4
+ import shutil
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ S = Path("/ssdstore/ssalehi/SynthScope")
9
+ OUT = S / "_demo_pack"
10
+ EXT = {".jpg", ".jpeg", ".png", ".webp", ".mp4", ".gif", ".mov"}
11
+
12
+
13
+ def pick(folder: Path, k: int) -> list[Path]:
14
+ files = sorted(p for p in folder.iterdir() if p.suffix.lower() in EXT and not p.name.startswith("._"))
15
+ if len(files) <= k:
16
+ return files
17
+ return [files[round(i * (len(files) - 1) / (k - 1))] for i in range(k)] if k > 1 else files[:1]
18
+
19
+
20
+ def copy(files, dest: Path):
21
+ dest.mkdir(parents=True, exist_ok=True)
22
+ for p in files:
23
+ shutil.copy2(p, dest / p.name)
24
+
25
+
26
+ PLAN = [ # (folder, per-class count, classes)
27
+ ("CommGen15", 6, ("0_real", "1_fake")),
28
+ ("RRDataset", 12, ("0_real", "1_fake")),
29
+ ("EvalGEN", 8, ("1_fake",)),
30
+ ("VideoPhy", 3, ("1_fake",)),
31
+ ]
32
+ shutil.rmtree(OUT, ignore_errors=True)
33
+ for folder, k, classes in PLAN:
34
+ for gen in sorted(p for p in (S / folder / "test").iterdir() if p.is_dir()):
35
+ for c in classes:
36
+ copy(pick(gen / c, k), OUT / folder / "test" / gen.name / c)
37
+ for gen in sorted(p for p in (S / "EvalCrafter" / "test" / "1_fake").iterdir() if p.is_dir()):
38
+ copy(pick(gen, 3), OUT / "EvalCrafter" / "test" / "1_fake" / gen.name)
39
+
40
+ (OUT / "README.md").write_text("""---
41
+ license: other
42
+ pretty_name: SynthScope online-demo data
43
+ ---
44
+ # SynthScope online-demo data
45
+
46
+ A small sample of public AI-generated-image and -video benchmarks for the dataset browser of the SynthScope online demo.
47
+ A local SynthScope install downloads the full datasets with one command each.
48
+
49
+ | Folder | Source | License | Sample |
50
+ |---|---|---|---|
51
+ | CommGen15 | PGC (Zhou et al.), Hugging Face `xiaoyuzhou68/CommGen15` | Apache-2.0 | 6 real + 6 generated per generator |
52
+ | RRDataset | "Bridging the Gap Between Ideal and Real-world Evaluation" (ICCV 2025), Zenodo record 14963880 | CC BY 4.0 | 12 real + 12 generated per scenario |
53
+ | EvalGEN | DDA (Chen et al., NeurIPS 2025), Hugging Face `Junwei-Xi/EvalGEN` | Apache-2.0 | 8 generated images per generator |
54
+ | EvalCrafter | EvalCrafter (Liu et al., CVPR 2024), Hugging Face `RaphaelLiu/EvalCrafter_T2V_Dataset` | Apache-2.0 | 3 generated clips per generator |
55
+ | VideoPhy | VideoPhy (Bansal et al., 2024), `videophysics/videophy_test_public` | MIT | 3 generated clips per generator |
56
+
57
+ All files are unchanged copies from those sources; credit belongs to their authors.
58
+ """)
59
+ n = sum(1 for p in OUT.rglob("*") if p.is_file())
60
+ size = sum(p.stat().st_size for p in OUT.rglob("*") if p.is_file())
61
+ print(f"demo pack: {n} files, {size / 1e6:.0f} MB at {OUT}")
62
+ for d in sorted(OUT.iterdir()):
63
+ if d.is_dir():
64
+ print(f" {d.name}: {sum(1 for p in d.rglob('*') if p.is_file())} files, "
65
+ f"{sum(p.stat().st_size for p in d.rglob('*') if p.is_file()) / 1e6:.0f} MB")
deploy/hf-space/start.sh CHANGED
@@ -2,14 +2,21 @@
2
  # Space entry point: fetch the approved detector weights, then serve the page on the port Spaces expect (7860).
3
  set -e
4
  python deploy/hf-space/fetch_weights.py
5
- # Openly licensed datasets for the "Browse datasets" tab, downloaded in the background (the tab appears once one is ready).
6
- # SYNTHSCOPE_SPACE_DATASETS="" turns this off.
 
 
7
  export SYNTHSCOPE_DATA_DIR=${SYNTHSCOPE_DATA_DIR:-$HOME/data}
8
  (
9
- for spec in ${SYNTHSCOPE_SPACE_DATASETS-image:commgen15:CommGen15 video:evalcrafter:EvalCrafter}; do
10
- IFS=: read -r modality name folder <<< "$spec"
11
- python benchmark/download_dataset.py "$name" --modality "$modality" --root "$SYNTHSCOPE_DATA_DIR/$folder" \
12
- > "$HOME/download_$name.log" 2>&1 && echo "[data] $name ready" || echo "[data] $name failed (see $HOME/download_$name.log)"
13
- done
 
 
 
 
 
14
  ) &
15
  exec python -m uvicorn interface.backend.app:app --host 0.0.0.0 --port 7860
 
2
  # Space entry point: fetch the approved detector weights, then serve the page on the port Spaces expect (7860).
3
  set -e
4
  python deploy/hf-space/fetch_weights.py
5
+ # Data for the "Browse datasets" tab. By default a small demo pack (a few files per generator from several openly licensed
6
+ # benchmarks, ~a few hundred MB) is fetched from the Hugging Face dataset repo SYNTHSCOPE_DEMO_DATA_REPO. Setting
7
+ # SYNTHSCOPE_SPACE_DATASETS (e.g. "image:commgen15:CommGen15") instead downloads those full datasets with their loaders.
8
+ # Both run in the background; the tab appears once a dataset is ready.
9
  export SYNTHSCOPE_DATA_DIR=${SYNTHSCOPE_DATA_DIR:-$HOME/data}
10
  (
11
+ if [ -n "${SYNTHSCOPE_SPACE_DATASETS:-}" ]; then
12
+ for spec in $SYNTHSCOPE_SPACE_DATASETS; do
13
+ IFS=: read -r modality name folder <<< "$spec"
14
+ python benchmark/download_dataset.py "$name" --modality "$modality" --root "$SYNTHSCOPE_DATA_DIR/$folder" \
15
+ > "$HOME/download_$name.log" 2>&1 && echo "[data] $name ready" || echo "[data] $name failed (see $HOME/download_$name.log)"
16
+ done
17
+ elif [ -n "${SYNTHSCOPE_DEMO_DATA_REPO-SMSD75/synthscope-demo-data}" ]; then
18
+ python -c "import os; from huggingface_hub import snapshot_download; snapshot_download(os.environ.get('SYNTHSCOPE_DEMO_DATA_REPO', 'SMSD75/synthscope-demo-data'), repo_type='dataset', local_dir=os.environ['SYNTHSCOPE_DATA_DIR'], token=os.environ.get('HF_TOKEN'))" \
19
+ > "$HOME/download_demo_data.log" 2>&1 && echo "[data] demo pack ready" || echo "[data] demo pack failed (see $HOME/download_demo_data.log)"
20
+ fi
21
  ) &
22
  exec python -m uvicorn interface.backend.app:app --host 0.0.0.0 --port 7860
interface/static/index.html CHANGED
@@ -559,6 +559,7 @@ pre.cmd { margin: 10px 0 0; padding: 10px 12px; background: rgba(0,0,0,.35); bor
559
  // SOTA generator vs detector: pick/upload a real image -> a generator makes a new image ONCE -> any number of
560
  // detectors score the pair. Ticking another detector only scores it (no regeneration).
561
  const SETUP_URL = "https://github.com/SMSD75/SynthScope#readme";
 
562
 
563
  // Shown instead of "Test a generator" when no generator can run on this server (no GPU and no API key).
564
  function GeneratorOff({ demo }) {
@@ -1166,7 +1167,8 @@ pre.cmd { margin: 10px 0 0; padding: 10px 12px; background: rgba(0,0,0,.35); bor
1166
  return html`
1167
  <div class="explore">
1168
  ${demo && html`<div class="card notice slim">
1169
- <b>Demo subset.</b> To keep this online demo light it includes only ${datasets.map(d => d.name).join(" and ")}.
 
1170
  ${" "}Run SynthScope on your own computer and it downloads and browses every supported benchmark
1171
  ${supported ? ` (${supported.image} image and ${supported.video} video datasets)` : ""}, each with one command;
1172
  see the <a href=${SETUP_URL} target="_blank" rel="noopener">setup guide</a>.
 
559
  // SOTA generator vs detector: pick/upload a real image -> a generator makes a new image ONCE -> any number of
560
  // detectors score the pair. Ticking another detector only scores it (no regeneration).
561
  const SETUP_URL = "https://github.com/SMSD75/SynthScope#readme";
562
+ const listNames = xs => xs.length < 2 ? (xs[0] || "") : xs.slice(0, -1).join(", ") + " and " + xs[xs.length - 1];
563
 
564
  // Shown instead of "Test a generator" when no generator can run on this server (no GPU and no API key).
565
  function GeneratorOff({ demo }) {
 
1167
  return html`
1168
  <div class="explore">
1169
  ${demo && html`<div class="card notice slim">
1170
+ <b>Demo subset.</b> To keep this online demo light it includes a few files per generator from
1171
+ ${" "}${listNames(datasets.map(d => d.name.split(" (")[0]))}.
1172
  ${" "}Run SynthScope on your own computer and it downloads and browses every supported benchmark
1173
  ${supported ? ` (${supported.image} image and ${supported.video} video datasets)` : ""}, each with one command;
1174
  see the <a href=${SETUP_URL} target="_blank" rel="noopener">setup guide</a>.