yeq6x commited on
Commit
4a514b8
·
1 Parent(s): 2655454

Enhance app.py by implementing a logging mechanism for training progress and model performance metrics. This addition improves monitoring capabilities during training sessions and aids in debugging.

Browse files
Files changed (1) hide show
  1. ui_preview.py +78 -0
ui_preview.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Minimal UI preview launcher for app.py.
4
+
5
+ Purpose:
6
+ - Avoids heavy startup work (clones, downloads) by stubbing modules.
7
+ - Replaces training function with a no-op so you can safely click around.
8
+
9
+ Usage:
10
+ python ui_preview.py
11
+
12
+ Requires:
13
+ pip install gradio
14
+ """
15
+
16
+ import sys
17
+ import types
18
+
19
+
20
+ # Stub out `spaces` so the @spaces.GPU decorator is a no-op
21
+ spaces_stub = types.ModuleType("spaces")
22
+
23
+ def _gpu_decorator(fn=None, *args, **kwargs):
24
+ # Supports both @spaces.GPU and @spaces.GPU(...)
25
+ if callable(fn):
26
+ return fn
27
+
28
+ def _wrap(f):
29
+ return f
30
+
31
+ return _wrap
32
+
33
+ spaces_stub.GPU = _gpu_decorator
34
+ sys.modules["spaces"] = spaces_stub
35
+
36
+
37
+ # Stub out download_qwen_image_models to avoid importing huggingface_hub
38
+ models_stub = types.ModuleType("download_qwen_image_models")
39
+ models_stub.DEFAULT_MODELS_DIR = "./_models_stub"
40
+
41
+ def _download_all_models(models_dir: str = models_stub.DEFAULT_MODELS_DIR):
42
+ # Return a minimal shape that callers might expect; no downloads.
43
+ return {"root": models_dir}
44
+
45
+ models_stub.download_all_models = _download_all_models
46
+ sys.modules["download_qwen_image_models"] = models_stub
47
+
48
+
49
+ # Import the real app after stubbing
50
+ import gradio as gr # ensure gradio is installed
51
+ import importlib
52
+
53
+ app = importlib.import_module("app")
54
+
55
+
56
+ # Replace heavy training routine with a preview-friendly stub
57
+ def _preview_run_training(*args, **kwargs):
58
+ # Generator to match Gradio streaming handler expectations
59
+ msg = (
60
+ "[UI PREVIEW]\n"
61
+ "This is a UI-only preview. Training is disabled here.\n"
62
+ "Click handlers are stubbed; no jobs will run.\n"
63
+ )
64
+ yield (msg, [], None)
65
+
66
+
67
+ app.run_training = _preview_run_training # type: ignore[attr-defined]
68
+
69
+
70
+ def main():
71
+ ui: gr.Blocks = app.build_ui()
72
+ # For preview, simple launch without queue or allowed_paths
73
+ ui.launch()
74
+
75
+
76
+ if __name__ == "__main__":
77
+ main()
78
+