| import gradio as gr |
| import subprocess |
| import os |
| import time |
| import shutil |
| from huggingface_hub import HfApi, snapshot_download, list_repo_files |
|
|
| |
| STORAGE_REPO = "arudradey/flst" |
| LOCAL_ROOT = "/tmp/emsdk" |
| DATA_DIR = "/data" |
|
|
| |
|
|
| def verify_and_repair_sdk(): |
| """Compares local /tmp/emsdk with arudradey/flst to ensure no files are missed.""" |
| print("π Starting Integrity Check against arudradey/flst...") |
| |
| if not os.path.exists(LOCAL_ROOT): |
| return "β Local SDK directory missing. Please run install/boot first." |
|
|
| try: |
| |
| repo_files = list_repo_files(repo_id=STORAGE_REPO, repo_type="model") |
| |
| |
| snapshot_download( |
| repo_id=STORAGE_REPO, |
| repo_type="model", |
| local_dir=LOCAL_ROOT, |
| token=os.environ.get("HF_TOKEN") |
| ) |
| |
| |
| local_count = 0 |
| for root, dirs, files in os.walk(LOCAL_ROOT): |
| local_count += len(files) |
| |
| return f"β
Integrity Verified. Repo files: {len(repo_files)} | Local files: {local_count}. System is 100% synced." |
| except Exception as e: |
| return f"β Integrity Check/Repair Failed: {e}" |
|
|
| def boot_system(): |
| """Initial boot logic: tries to pull from storage or clean-installs if empty.""" |
| if os.path.exists(os.path.join(LOCAL_ROOT, "upstream", "emscripten")): |
| return "β
SDK ready in RAM." |
|
|
| try: |
| print(f"π Checking Model Repo {STORAGE_REPO}...") |
| snapshot_download( |
| repo_id=STORAGE_REPO, |
| local_dir=LOCAL_ROOT, |
| token=os.environ.get("HF_TOKEN") |
| ) |
| if os.path.exists(os.path.join(LOCAL_ROOT, "emsdk_env.sh")): |
| return "π Fast-boot: SDK pulled from storage." |
| except Exception as e: |
| print(f"βΉοΈ Storage empty or inaccessible. Preparing fresh install...") |
|
|
| |
| if os.path.exists(LOCAL_ROOT): |
| shutil.rmtree(LOCAL_ROOT) |
| |
| print("π₯ Installing fresh SDK...") |
| subprocess.run(f"git clone https://github.com/emscripten-core/emsdk.git {LOCAL_ROOT}", shell=True, check=True) |
| subprocess.run(f"{LOCAL_ROOT}/emsdk install latest", shell=True, check=True) |
| subprocess.run(f"{LOCAL_ROOT}/emsdk activate latest", shell=True, check=True) |
| return "β
Fresh install complete." |
|
|
| def save_large_to_repo(): |
| """Uses Large Folder API to handle the 2.6GB and 50k+ files.""" |
| api = HfApi() |
| try: |
| api.upload_large_folder( |
| folder_path=LOCAL_ROOT, |
| repo_id=STORAGE_REPO, |
| repo_type="model", |
| token=os.environ.get("HF_TOKEN") |
| ) |
| return "π₯ Successfully saved 2.6GB build to arudradey/flst!" |
| except Exception as e: |
| return f"β Upload failed: {e}" |
|
|
| |
| boot_msg = boot_system() |
|
|
| |
| EMCC_BIN = os.path.join(LOCAL_ROOT, "upstream", "emscripten") |
| CLANG_DIR = os.path.join(LOCAL_ROOT, "upstream", "bin") |
| os.environ["PATH"] = f"{EMCC_BIN}:{CLANG_DIR}:" + os.environ["PATH"] |
|
|
| |
| with gr.Blocks(title="Emscripten Cloud") as demo: |
| gr.Markdown(f"### π‘οΈ SDK Control Center\n**Status:** {boot_msg}") |
| |
| with gr.Row(): |
| check_btn = gr.Button("π VERIFY INTEGRITY", variant="secondary") |
| save_btn = gr.Button("πΎ UPLOAD LARGE FOLDER", variant="primary") |
| test_btn = gr.Button("π§ͺ TEST COMPILER") |
| |
| logs = gr.Textbox(label="System Output", lines=12) |
|
|
| |
| check_btn.click(verify_and_repair_sdk, None, logs) |
| save_btn.click(save_large_to_repo, None, logs) |
| test_btn.click(lambda: subprocess.getoutput("emcc --version"), None, logs) |
|
|
| demo.launch() |