Spaces:
Running
on
Zero
Running
on
Zero
| #!/usr/bin/env python3 | |
| """ | |
| Minimal UI preview launcher for app.py. | |
| Purpose: | |
| - Avoids heavy startup work (clones, downloads) by stubbing modules. | |
| - Replaces training function with a no-op so you can safely click around. | |
| Usage: | |
| python ui_preview.py | |
| Requires: | |
| pip install gradio | |
| """ | |
| import sys | |
| import types | |
| # Stub out `spaces` so the @spaces.GPU decorator is a no-op | |
| spaces_stub = types.ModuleType("spaces") | |
| def _gpu_decorator(fn=None, *args, **kwargs): | |
| # Supports both @spaces.GPU and @spaces.GPU(...) | |
| if callable(fn): | |
| return fn | |
| def _wrap(f): | |
| return f | |
| return _wrap | |
| spaces_stub.GPU = _gpu_decorator | |
| sys.modules["spaces"] = spaces_stub | |
| # Stub out download_qwen_image_models to avoid importing huggingface_hub | |
| models_stub = types.ModuleType("download_qwen_image_models") | |
| models_stub.DEFAULT_MODELS_DIR = "./_models_stub" | |
| def _download_all_models(models_dir: str = models_stub.DEFAULT_MODELS_DIR): | |
| # Return a minimal shape that callers might expect; no downloads. | |
| return {"root": models_dir} | |
| models_stub.download_all_models = _download_all_models | |
| sys.modules["download_qwen_image_models"] = models_stub | |
| # Import the real app after stubbing | |
| import gradio as gr # ensure gradio is installed | |
| import importlib | |
| app = importlib.import_module("app") | |
| # Replace heavy training routine with a preview-friendly stub | |
| def _preview_run_training(*args, **kwargs): | |
| # Generator to match Gradio streaming handler expectations | |
| msg = ( | |
| "[UI PREVIEW]\n" | |
| "This is a UI-only preview. Training is disabled here.\n" | |
| "Click handlers are stubbed; no jobs will run.\n" | |
| ) | |
| yield (msg, [], None) | |
| app.run_training = _preview_run_training # type: ignore[attr-defined] | |
| def main(): | |
| ui: gr.Blocks = app.build_ui() | |
| # For preview, simple launch without queue or allowed_paths | |
| ui.launch() | |
| if __name__ == "__main__": | |
| main() | |