ameforge commited on
Commit
ebe5f6f
·
verified ·
1 Parent(s): de2eb67

app.py: bootstrap modules from private repo at startup

Browse files
Files changed (1) hide show
  1. app.py +50 -1
app.py CHANGED
@@ -5,9 +5,58 @@ Deploy on a Space (AMFORGE) so anyone can try GearCut in the browser.
5
  The model (gc_editor) and tokenizer are pulled from the AMFORGE HF repos at
6
  startup. ffmpeg is provided by packages.txt.
7
 
 
 
 
8
  Local run: python app.py
9
  """
10
- import os, json, uuid
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  import gearcut_compiler as gc
12
 
13
  _MODEL = None
 
5
  The model (gc_editor) and tokenizer are pulled from the AMFORGE HF repos at
6
  startup. ffmpeg is provided by packages.txt.
7
 
8
+ Core modules are loaded from a private HF repo at startup using HF_TOKEN secret.
9
+ Visitors can use the demo but cannot access the proprietary source code.
10
+
11
  Local run: python app.py
12
  """
13
+ import os
14
+ import sys
15
+ import json
16
+ import uuid
17
+
18
+ # ---- Bootstrap: download proprietary modules from private HF repo -----------
19
+ def _bootstrap_modules():
20
+ """Download gearcut_* modules from private AMFORGE/gearcut-core repo."""
21
+ token = os.environ.get("HF_TOKEN")
22
+ if not token:
23
+ print("[GearCut] WARNING: HF_TOKEN not set — assuming modules are local.")
24
+ return
25
+
26
+ modules = [
27
+ "gearcut_compiler.py",
28
+ "gearcut_model.py",
29
+ "gearcut_infer.py",
30
+ "gearcut_ground.py",
31
+ ]
32
+
33
+ # Check if already downloaded
34
+ if all(os.path.exists(m) for m in modules):
35
+ print("[GearCut] Core modules already present.")
36
+ return
37
+
38
+ print("[GearCut] Downloading core modules from private repo...")
39
+ try:
40
+ from huggingface_hub import hf_hub_download
41
+ for fname in modules:
42
+ if not os.path.exists(fname):
43
+ path = hf_hub_download(
44
+ repo_id="AMFORGE/gearcut-core",
45
+ filename=fname,
46
+ repo_type="dataset",
47
+ token=token,
48
+ local_dir=".",
49
+ )
50
+ print(f"[GearCut] ✓ {fname} downloaded")
51
+ else:
52
+ print(f"[GearCut] ✓ {fname} already exists")
53
+ except Exception as e:
54
+ print(f"[GearCut] ERROR downloading modules: {e}")
55
+ sys.exit(1)
56
+
57
+ _bootstrap_modules()
58
+
59
+ # ---- Now import the proprietary modules ------------------------------------
60
  import gearcut_compiler as gc
61
 
62
  _MODEL = None