glb-studio / deploy_to_hf.py
GLB Studio Deploy
add: deploy_to_hf.py β€” one-file Colab deployer (token placeholder)
43b9bcb
Raw
History Blame Contribute Delete
6.2 kB
"""
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