Spaces:
Running on Zero
Running on Zero
Download tests/test_simple_ui.py from Simzy/Wan-2.2-Studio: direct link, hf CLI and curl.
- Browser
- Download file 5.94 kB
-
https://huggingface.co/spaces/Simzy/Wan-2.2-Studio/resolve/main/tests/test_simple_ui.py
- Command line
-
hf download hf://spaces/Simzy/Wan-2.2-Studio/tests/test_simple_ui.py
-
curl -L -o test_simple_ui.py https://huggingface.co/spaces/Simzy/Wan-2.2-Studio/resolve/main/tests/test_simple_ui.py
5.94 kB
| """Build the real Gradio components without importing the inference pipeline.""" | |
| import ast | |
| from collections import Counter | |
| from pathlib import Path | |
| import unittest | |
| from unittest.mock import patch | |
| import gradio as gr | |
| import lora_library | |
| from economy_prompt import ECONOMY_NOTE | |
| from prompt_assistant import assistant_choices | |
| ROOT = Path(__file__).resolve().parents[1] | |
| SOURCE = ROOT / "app.py" | |
| TREE = ast.parse(SOURCE.read_text(encoding="utf-8")) | |
| class UIOnly(ast.NodeTransformer): | |
| def visit_Expr(self, node): | |
| # Keep the actual library tab and its event wiring. Its prompt input is | |
| # constructed with render=False and rendered once later in the workspace. | |
| call = node.value | |
| if isinstance(call, ast.Call) and isinstance(call.func, ast.Attribute): | |
| if call.func.attr in ("click", "change", "input", "submit", "select", "release", | |
| "blur", "upload", "then", "success", "failure"): | |
| return None | |
| return self.generic_visit(node) | |
| def build_ui(): | |
| node = next(n for n in TREE.body if isinstance(n, ast.With) and any( | |
| isinstance(item.context_expr, ast.Call) and isinstance(item.context_expr.func, ast.Attribute) | |
| and item.context_expr.func.attr == "Blocks" for item in n.items)) | |
| end = next(i for i, n in enumerate(node.body) if isinstance(n, ast.Assign) | |
| and any(isinstance(t, ast.Name) and t.id == "ui_inputs" for t in n.targets)) | |
| node = ast.With(items=node.items, body=node.body[:end], type_comment=None) | |
| module = ast.fix_missing_locations(UIOnly().visit(ast.Module(body=[node], type_ignores=[]))) | |
| ns = {"gr": gr, "assistant_choices": assistant_choices, "ECONOMY_NOTE": ECONOMY_NOTE, | |
| "REMOTE_SPACE": "amisima/Qwen3.8-27B-Uncensored-Demo", "CSS": "", "HERO": "Feature tour", | |
| "LORA_MAX_FILE_BYTES": 500 * 1048576, "LORA_MAX_RUN_BYTES": 1000 * 1048576, | |
| "default_prompt_i2v": "make this image come alive", "default_negative_prompt": "", | |
| "list_profiles": lambda: [], "NO_PROFILE": "none", "MIN_DURATION": .5, | |
| "MAX_DURATION": 20.1, "MAX_SCENE_CLIPS": 64, "FIXED_FPS": 16, "MAX_SEED": 2**31-1, | |
| "STARTER_NONE": "none", "STARTER_RECIPES": {}, "SPEED_NONE": "none", "SPEED_PRESETS": {"none": {}}, | |
| "CAMERA_MOVES": {"(keep as written)": ""}, "FRAMINGS": {"(keep as written)": ""}, | |
| "LIGHTING": {"(keep as written)": ""}, "PACING": {"(keep as written)": ""}, | |
| "PROMPT_CHIPS": [], "LORA_CHOICES": ["(None)"], "SCHEDULER_MAP": {"UniPCMultistep": None}, | |
| "WAN_BASE_MODELS": ["Wan 2.2"], "FOLEY_ENGINES": {"Audio": {}}, "FOLEY_DEFAULT": "Audio", | |
| "FOLEY_NEGATIVE": "", "lora_library": lora_library} | |
| with patch.object(lora_library, "load_library", return_value={"normal": [], "nsfw": []}): | |
| exec(compile(module, str(SOURCE), "exec"), ns) | |
| return ns | |
| class SimpleUITests(unittest.TestCase): | |
| def setUpClass(cls): | |
| cls.ns = build_ui() | |
| cls.config = cls.ns["demo"].config | |
| def tearDownClass(cls): | |
| cls.ns["demo"].close() | |
| def test_single_collapsed_settings_and_same_essential_instances(self): | |
| ns = self.ns | |
| self.assertFalse(ns["more_settings"].open) | |
| top = self.config["layout"]["children"] | |
| self.assertEqual(sum(n["id"] == ns["more_settings"]._id for n in top), 1) | |
| workspace = next(n for n in top if n["id"] == ns["simple_workspace"]._id) | |
| settings = next(n for n in top if n["id"] == ns["more_settings"]._id) | |
| def ids(node): | |
| return [node["id"]] + [i for c in node.get("children", []) for i in ids(c)] | |
| all_ids = ids(self.config["layout"]) | |
| self.assertFalse([i for i, count in Counter(all_ids).items() if count > 1]) | |
| essential = ("input_image_component", "prompt_input", "duration_seconds_input", | |
| "generate_button", "video_output", "file_output", "status_box") | |
| for name in essential: | |
| self.assertIn(ns[name]._id, ids(workspace), name) | |
| self.assertNotIn(ns[name]._id, ids(settings), name) | |
| self.assertEqual(all_ids.count(ns[name]._id), 1, name) | |
| for name in ("pb_space", "basic_btn", "simple_lora", "lora1_high_scale", "my5_ls", | |
| "profile_picker", "sound_prompt", "identity_strength_slider", "extension_prompt", | |
| "scene_idea", "gpu_estimate", "safe_mode_checkbox"): | |
| self.assertIn(ns[name]._id, ids(settings), name) | |
| self.assertNotIn(ns[name]._id, ids(workspace), name) | |
| self.assertFalse(ns["studio_tour"].visible) | |
| def test_defaults_and_generation_event_keep_existing_components(self): | |
| ns = self.ns | |
| self.assertEqual(ns["pb_space"].value, "amisima/Qwen3.8-27B-Uncensored-Demo") | |
| self.assertEqual(ns["generate_button"].value, "Generate") | |
| self.assertEqual(ns["duration_seconds_input"].value, 3.5) | |
| self.assertEqual(ns["steps_slider"].value, 6) | |
| self.assertTrue(ns["prompt_input"].value) | |
| ui_inputs = next(n.value for n in ast.walk(TREE) if isinstance(n, ast.Assign) | |
| and any(isinstance(t, ast.Name) and t.id == "ui_inputs" for t in n.targets)) | |
| self.assertEqual([n.id for n in ui_inputs.elts[:3]], | |
| ["input_image_component", "last_image_component", "prompt_input"]) | |
| self.assertEqual(len(ns["pb_space"].choices), 2) | |
| self.assertIn("private test", ns["pb_space"].choices[1][0]) | |
| def test_library_callbacks_use_the_same_prompt_before_it_is_rendered(self): | |
| prompt_id = self.ns["prompt_input"]._id | |
| dependencies = self.config["dependencies"] | |
| self.assertTrue(any(prompt_id in event["inputs"] for event in dependencies)) | |
| self.assertTrue(any(prompt_id in event["outputs"] for event in dependencies)) | |
| if __name__ == "__main__": | |
| unittest.main() | |