| import os |
| import shutil |
| import subprocess |
| import sys |
| from huggingface_hub import snapshot_download |
|
|
| PRIVATE_REPO_ID = "HongshengY/NeuralSketch2Surf" |
| HF_TOKEN = os.environ.get("HF_TOKEN") |
|
|
| APP_DIR = "/tmp/private_app" |
|
|
| def main(): |
| if not HF_TOKEN: |
| print("HF_TOKEN not detected") |
| sys.exit(1) |
|
|
| print(f"Loading latest code from private repository {PRIVATE_REPO_ID}...") |
|
|
| try: |
| if os.path.exists(APP_DIR): |
| shutil.rmtree(APP_DIR) |
|
|
| snapshot_download( |
| repo_id=PRIVATE_REPO_ID, |
| repo_type="space", |
| revision="main", |
| local_dir=APP_DIR, |
| token=HF_TOKEN, |
| force_download=True, |
| ) |
|
|
| print("Code and model download complete!") |
|
|
| os.chdir(APP_DIR) |
|
|
| if os.path.exists("backend/requirements.txt"): |
| print("Installing backend/requirements.txt...") |
| subprocess.run( |
| [sys.executable, "-m", "pip", "install", "-r", "backend/requirements.txt"], |
| check=True |
| ) |
|
|
| print("Starting NeuralSketch2Surf Web...") |
|
|
| cmd = [ |
| "uvicorn", |
| "backend.server:app", |
| "--host", "0.0.0.0", |
| "--port", "7860" |
| ] |
|
|
| os.execvp("uvicorn", cmd) |
|
|
| except Exception as e: |
| print(f"An error occurred: {e}") |
| sys.exit(1) |
|
|
| if __name__ == "__main__": |
| main() |