Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,906 Bytes
4a514b8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#!/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()
|