Spaces:
Running
Running
| """ | |
| GLB Studio β HF Spaces Deployer | |
| Run this in Google Colab: https://colab.research.google.com | |
| Copy this entire file, paste into a new Colab notebook, Run All. | |
| """ | |
| import subprocess, sys, os, shutil, time | |
| # ββ Install ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "huggingface_hub>=0.23.0"]) | |
| from huggingface_hub import HfApi, upload_folder | |
| from huggingface_hub.utils import RepositoryNotFoundError | |
| # ββ Config βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| HF_TOKEN = "YOUR_HF_TOKEN_HERE" # get from huggingface.co/settings/tokens | |
| HF_USERNAME = "varunm2004" | |
| SPACE_NAME = "glb-studio" | |
| GITHUB_URL = "https://github.com/varunmulay-droid/glb-studio.git" | |
| SPACE_ID = f"{HF_USERNAME}/{SPACE_NAME}" | |
| SPACE_URL = f"https://huggingface.co/spaces/{SPACE_ID}" | |
| print(f"Target: {SPACE_URL}\n") | |
| # ββ Authenticate βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| api = HfApi(token=HF_TOKEN) | |
| try: | |
| user = api.whoami() | |
| print(f"β Logged in as @{user['name']}") | |
| except Exception as e: | |
| raise SystemExit(f"β Auth failed: {e}\nGet a token at: huggingface.co/settings/tokens") | |
| # ββ Ensure Space exists ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| try: | |
| api.space_info(SPACE_ID) | |
| print("β Space found") | |
| except RepositoryNotFoundError: | |
| print(f"Creating Space: {SPACE_ID}") | |
| api.create_repo(repo_id=SPACE_NAME, repo_type="space", space_sdk="docker", private=False) | |
| time.sleep(5) | |
| print("β Space created") | |
| # ββ Clone latest source ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| SRC = "/content/glb_src" | |
| if os.path.exists(SRC): | |
| shutil.rmtree(SRC) | |
| print("π₯ Cloning from GitHub...") | |
| r = subprocess.run(["git","clone","--depth=1", GITHUB_URL, SRC], capture_output=True, text=True) | |
| if r.returncode != 0: | |
| raise SystemExit(f"β Clone failed:\n{r.stderr}") | |
| # Show what we cloned | |
| log = subprocess.run(["git","-C",SRC,"log","--oneline","-3"], capture_output=True, text=True) | |
| print(f"Latest commits:\n{log.stdout}") | |
| # Verify dist/ present | |
| dist_path = os.path.join(SRC, "dist") | |
| if os.path.isdir(dist_path): | |
| assets = os.listdir(os.path.join(dist_path, "assets")) | |
| print(f"β dist/ found β {len(assets)} pre-built assets (no npm needed on HF)") | |
| else: | |
| print("β οΈ dist/ missing from repo") | |
| # ββ Overwrite README with valid HF front-matter ββββββββββββββββββββββββββββββββ | |
| readme = """\ | |
| --- | |
| title: Glb Studio | |
| emoji: π¬ | |
| colorFrom: blue | |
| colorTo: indigo | |
| sdk: docker | |
| app_port: 7860 | |
| pinned: false | |
| license: mit | |
| short_description: GLB 3D Animation Studio β Three.js + React | |
| --- | |
| # π¬ GLB Animation Studio | |
| Professional browser-based 3D animation studio for GLB/GLTF models. | |
| ## Features | |
| - GLB/GLTF loading Β· Transform controls Β· Keyframe animation with easing | |
| - Multi-camera system with fly controls Β· Camera path animation | |
| - Cannon.js physics: gravity, mass, damping, impulse | |
| - AI scene controller (OpenRouter free models) | |
| - Material editor Β· Undo/Redo Β· Project save/load | |
| - Clean render mode: grid/gizmos/rings hidden during export | |
| - Video export (WebM) Β· PNG sequence | |
| - Mobile optimised | |
| ## Tech Stack | |
| React 18 Β· Vite Β· Three.js Β· React Three Fiber Β· Zustand Β· nginx Β· Docker | |
| """ | |
| with open(os.path.join(SRC, "README.md"), "w") as f: | |
| f.write(readme) | |
| print("β README.md written") | |
| # ββ Upload βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| print("\nπ Uploading to HF Space...") | |
| print(" (includes pre-built dist/ β HF build takes ~20 seconds)\n") | |
| try: | |
| commit = upload_folder( | |
| folder_path = SRC, | |
| repo_id = SPACE_ID, | |
| repo_type = "space", | |
| token = HF_TOKEN, | |
| commit_message = "π¬ GLB Studio: pre-built, nginx-only, all bugs fixed", | |
| ignore_patterns = [ | |
| ".git", ".git/**", | |
| "node_modules/**", | |
| "*.log", ".DS_Store", | |
| ".github/**", | |
| "standalone.html", | |
| "deployer_app.py", | |
| "docker-compose.yml", | |
| "Dockerfile.dev", | |
| "DEPLOY.md", | |
| "deploy_to_hf.py", | |
| ], | |
| ) | |
| print(f""" | |
| ββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β β DEPLOYED SUCCESSFULLY! β | |
| β βββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β π {SPACE_URL:<36} β | |
| β β± HF Docker build: ~20 seconds β | |
| β π Watch: Logs tab β Build subtab β | |
| β β | |
| β The Dockerfile just runs nginx to serve β | |
| β the pre-built files β no npm install! β | |
| ββββββββββββββββββββββββββββββββββββββββββββββββ | |
| """) | |
| except Exception as e: | |
| err = str(e) | |
| print(f"\nβ Upload failed:\n{err}") | |
| if "401" in err or "403" in err: | |
| print("\nπ‘ Token fix:") | |
| print(" β huggingface.co/settings/tokens") | |
| print(" β Edit token β Repository access") | |
| print(f" β Add {SPACE_ID} with Write permission") | |
| raise | |