Spaces:
Sleeping
Sleeping
Simplify default workspace and add optional private Economy caption test
Browse files- README.md +10 -2
- app.py +0 -0
- economy_prompt.py +65 -0
- prompt_assistant.py +2 -1
- tests/test_economy_prompt.py +149 -0
- tests/test_profiles_and_queue.py +4 -0
- tests/test_prompt_assistant.py +5 -3
- tests/test_remote_writer_isolation.py +24 -0
- tests/test_simple_ui.py +111 -0
README.md
CHANGED
|
@@ -24,8 +24,16 @@ tags:
|
|
| 24 |
|
| 25 |
**One image. One idea. A scene built in stages.**
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
**🆕 AI Scene Planner · 🔒 Improved Identity Lock · 🔊 3 audio models · 🎞️ Up to 64 clips**
|
| 31 |
|
|
|
|
| 24 |
|
| 25 |
**One image. One idea. A scene built in stages.**
|
| 26 |
|
| 27 |
+
Upload an image, describe what should happen, choose the video length and press **Generate**.
|
| 28 |
+
The complete set of controls is available in the collapsed **More settings** section.
|
| 29 |
+
The same controls, saved profiles, LoRAs, Identity Lock, audio and Extend tools remain available.
|
| 30 |
+
|
| 31 |
+
**Optional image assistant:** Qwen3.8 remains selected by default. More settings also offers
|
| 32 |
+
the dedicated CPU caption assistant when you have access to its Space. It makes one image
|
| 33 |
+
description request, capped at 384 tokens with temperature 0, and preserves your original
|
| 34 |
+
instructions, LoRA selection and strengths. With text alone it keeps the description without
|
| 35 |
+
an AI request. It does not translate or plan scenes, choose LoRAs, tune strengths or write
|
| 36 |
+
sound descriptions; those AI tasks require Qwen3.8. There is no automatic retry or fallback.
|
| 37 |
|
| 38 |
**🆕 AI Scene Planner · 🔒 Improved Identity Lock · 🔊 3 audio models · 🎞️ Up to 64 clips**
|
| 39 |
|
app.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
economy_prompt.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pure helpers for the optional CPU image-caption assistant.
|
| 2 |
+
|
| 3 |
+
No clients, credentials, model calls or adapter changes live in this module.
|
| 4 |
+
"""
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
ECONOMY_SPACE = "amisima/Qwen3.5-Picture-Captioner"
|
| 8 |
+
ECONOMY_LABEL = "Super Economy - private test"
|
| 9 |
+
ECONOMY_TOKENS = 384
|
| 10 |
+
ECONOMY_NOTE = (
|
| 11 |
+
"Private test: this helper currently requires access to the owner's test Space. "
|
| 12 |
+
"It is not yet enabled for public visitors. "
|
| 13 |
+
"Super Economy describes reference images on CPU without using ZeroGPU quota. "
|
| 14 |
+
"It keeps your idea, LoRAs and strengths. With text alone it keeps your original "
|
| 15 |
+
"description without an AI call. Use Qwen3.8 for detailed rewriting, translation "
|
| 16 |
+
"and automatic LoRA choices. Review the small model's image description."
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def is_economy(writer):
|
| 21 |
+
value = str(writer or "").strip().rstrip("/")
|
| 22 |
+
for prefix in ("https://huggingface.co/spaces/", "http://huggingface.co/spaces/"):
|
| 23 |
+
if value.lower().startswith(prefix):
|
| 24 |
+
value = value[len(prefix):]
|
| 25 |
+
break
|
| 26 |
+
return value.casefold() == ECONOMY_SPACE.casefold()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def economy_instruction(idea="", kind="video", has_image=True):
|
| 30 |
+
"""Caption only; do not make this small model interpret adapter catalogues."""
|
| 31 |
+
if not has_image:
|
| 32 |
+
raise ValueError("Text-only Economy uses the original idea without an AI call.")
|
| 33 |
+
return (
|
| 34 |
+
"Describe this reference image in one concise English paragraph, at most 70 words. "
|
| 35 |
+
"Describe the visible subjects, clothes, pose, setting and lighting. "
|
| 36 |
+
"Only describe what is visible. Do not invent dialogue, movement or extra objects. "
|
| 37 |
+
"Return only the description, without headings, lists, JSON or settings."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def economy_prompt(caption, original, controls=""):
|
| 42 |
+
"""Keep the user's exact instructions independently of the model's caption."""
|
| 43 |
+
original = str(original or "").strip()
|
| 44 |
+
caption = str(caption or "").strip()
|
| 45 |
+
if caption:
|
| 46 |
+
if caption.startswith(("{", "[")) or any(
|
| 47 |
+
label in caption.upper() for label in ("STRENGTHS:", "PICKS:")
|
| 48 |
+
):
|
| 49 |
+
raise ValueError("The Economy assistant returned settings instead of an image description.")
|
| 50 |
+
parts = ["Reference appearance: " + caption]
|
| 51 |
+
if original:
|
| 52 |
+
parts.append("Requested action or changes (these take precedence over the reference appearance): " + original)
|
| 53 |
+
else:
|
| 54 |
+
parts = [original] if original else []
|
| 55 |
+
if controls:
|
| 56 |
+
parts.append(str(controls))
|
| 57 |
+
if not parts:
|
| 58 |
+
raise ValueError("Enter a description or attach a reference image.")
|
| 59 |
+
return "\n\n".join(parts)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def economy_status(has_image):
|
| 63 |
+
if has_image:
|
| 64 |
+
return "Super Economy: image described on CPU. Review the description. Your LoRAs and strengths were kept."
|
| 65 |
+
return "Super Economy: your original description was kept; no AI call was made. Your LoRAs and strengths were kept."
|
prompt_assistant.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
DEFAULT_WRITER_SPACE = "amisima/Qwen3.8-27B-Uncensored-Demo"
|
| 7 |
|
|
@@ -28,7 +29,7 @@ def resolve_writer(writer):
|
|
| 28 |
|
| 29 |
|
| 30 |
def assistant_choices(qwen_space):
|
| 31 |
-
return [("Qwen3.8", resolve_writer(qwen_space))]
|
| 32 |
|
| 33 |
|
| 34 |
def supports_images(writer):
|
|
|
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
import os
|
| 5 |
+
from economy_prompt import ECONOMY_SPACE, ECONOMY_LABEL
|
| 6 |
|
| 7 |
DEFAULT_WRITER_SPACE = "amisima/Qwen3.8-27B-Uncensored-Demo"
|
| 8 |
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def assistant_choices(qwen_space):
|
| 32 |
+
return [("Qwen3.8", resolve_writer(qwen_space)), (ECONOMY_LABEL, ECONOMY_SPACE)]
|
| 33 |
|
| 34 |
|
| 35 |
def supports_images(writer):
|
tests/test_economy_prompt.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Offline routing checks: no weights, network calls, or inference are loaded."""
|
| 2 |
+
import ast
|
| 3 |
+
import inspect
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import types
|
| 7 |
+
import tempfile
|
| 8 |
+
import unittest
|
| 9 |
+
from unittest.mock import Mock
|
| 10 |
+
|
| 11 |
+
import economy_prompt as economy
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
TREE = ast.parse((ROOT / "app.py").read_text(encoding="utf-8"))
|
| 15 |
+
FUNCTIONS = {node.name: node for node in ast.walk(TREE) if isinstance(node, ast.FunctionDef)}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def namespace(*names):
|
| 19 |
+
values = {name: getattr(economy, name) for name in (
|
| 20 |
+
"ECONOMY_SPACE", "ECONOMY_TOKENS", "is_economy", "economy_instruction",
|
| 21 |
+
"economy_prompt", "economy_status")}
|
| 22 |
+
values.update(gr=types.SimpleNamespace(
|
| 23 |
+
update=lambda **kwargs: {"__type__": "update", **kwargs},
|
| 24 |
+
Error=ValueError, Progress=lambda: (lambda *args, **kwargs: None)),
|
| 25 |
+
_remote_ask=Mock(return_value="A woman in a red coat stands beside a window."))
|
| 26 |
+
nodes = [FUNCTIONS[name] for name in names]
|
| 27 |
+
exec(compile(ast.Module(nodes, type_ignores=[]), str(ROOT / "app.py"), "exec"), values)
|
| 28 |
+
return values
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def invoke(function, **overrides):
|
| 32 |
+
values = {name: None for name, arg in inspect.signature(function).parameters.items()
|
| 33 |
+
if arg.kind not in (arg.VAR_POSITIONAL, arg.VAR_KEYWORD) and arg.default is arg.empty}
|
| 34 |
+
values.update(overrides)
|
| 35 |
+
return function(**values)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class EconomyPromptTests(unittest.TestCase):
|
| 39 |
+
def test_text_only_is_exact_original_and_never_calls_ai(self):
|
| 40 |
+
ns = namespace("_economy_wan_prompt")
|
| 41 |
+
idea = 'Тя казва "Здравей". Exactly two people; no music.'
|
| 42 |
+
prompt, status = ns["_economy_wan_prompt"](idea, None)
|
| 43 |
+
self.assertEqual(prompt, idea)
|
| 44 |
+
self.assertIn("no AI call", status)
|
| 45 |
+
ns["_remote_ask"].assert_not_called()
|
| 46 |
+
|
| 47 |
+
def test_image_is_one_caption_only_call_with_fixed_budget(self):
|
| 48 |
+
ns = namespace("_economy_wan_prompt")
|
| 49 |
+
image = object()
|
| 50 |
+
idea = 'He says "Добър ден"; no extra people.'
|
| 51 |
+
prompt, status = ns["_economy_wan_prompt"](idea, image)
|
| 52 |
+
ns["_remote_ask"].assert_called_once_with(
|
| 53 |
+
economy.ECONOMY_SPACE, economy.economy_instruction(), image,
|
| 54 |
+
temperature=0.0, max_new_tokens=384)
|
| 55 |
+
self.assertIn(idea, prompt)
|
| 56 |
+
self.assertIn("were kept", status)
|
| 57 |
+
self.assertNotIn(idea, ns["_remote_ask"].call_args.args[1])
|
| 58 |
+
|
| 59 |
+
def test_main_and_extend_keep_every_adapter_and_state_output(self):
|
| 60 |
+
ns = namespace("_economy_wan_prompt", "_prepare_wan")
|
| 61 |
+
names = ["prompt_input", "extension_prompt", "basic_status", "extension_pick_status",
|
| 62 |
+
"basic_shortlist", "simple_lora", "scene_prompts", "manual_repo", "high_strength", "low_strength"]
|
| 63 |
+
ns.update({name: name for name in names})
|
| 64 |
+
ns["_PREPARE_OUTPUTS"] = names
|
| 65 |
+
for continuation in (False, True):
|
| 66 |
+
with self.subTest(continuation=continuation):
|
| 67 |
+
result = invoke(ns["_prepare_wan"], prompt="Exact original", image=None,
|
| 68 |
+
space_id=economy.ECONOMY_SPACE, continuation=continuation,
|
| 69 |
+
state={"applied": [{"name": "Manual", "strength": .65}]})
|
| 70 |
+
result = dict(zip(names, result))
|
| 71 |
+
changed = {"extension_prompt", "extension_pick_status"} if continuation else {"prompt_input", "basic_status"}
|
| 72 |
+
for name in names:
|
| 73 |
+
if name not in changed:
|
| 74 |
+
self.assertEqual(result[name], {"__type__": "update"})
|
| 75 |
+
ns["_remote_ask"].assert_not_called()
|
| 76 |
+
|
| 77 |
+
def test_legacy_helper_preserves_all_strengths(self):
|
| 78 |
+
ns = namespace("_economy_wan_prompt", "_big_space_run", "enhance_prompt")
|
| 79 |
+
result = invoke(ns["_big_space_run"], prompt="Exact original", space_id=economy.ECONOMY_SPACE)
|
| 80 |
+
self.assertEqual(result[0], "Exact original")
|
| 81 |
+
self.assertEqual(result[2:], [{"__type__": "update"}] * 17)
|
| 82 |
+
result = invoke(ns["enhance_prompt"], prompt="Exact original", use_model=True,
|
| 83 |
+
space_id=economy.ECONOMY_SPACE)
|
| 84 |
+
self.assertEqual(result[0], "Exact original")
|
| 85 |
+
ns["_remote_ask"].assert_not_called()
|
| 86 |
+
|
| 87 |
+
def test_unsupported_tasks_stop_before_any_work(self):
|
| 88 |
+
for name in ("plan_scene", "prepare_uploaded_sound_prompt", "_ask_which_loras", "_pick_ui", "_read_effects_model"):
|
| 89 |
+
with self.subTest(task=name):
|
| 90 |
+
ns = namespace(name)
|
| 91 |
+
with self.assertRaisesRegex(ValueError, "Qwen3.8 in More settings"):
|
| 92 |
+
invoke(ns[name], space_id=economy.ECONOMY_SPACE)
|
| 93 |
+
ns["_remote_ask"].assert_not_called()
|
| 94 |
+
|
| 95 |
+
def test_strength_heuristic_is_disabled_for_economy(self):
|
| 96 |
+
ns = namespace("_read_effects")
|
| 97 |
+
result = invoke(ns["_read_effects"], space_id=economy.ECONOMY_SPACE)
|
| 98 |
+
self.assertEqual(result, [{"__type__": "update"}] * 17)
|
| 99 |
+
|
| 100 |
+
def test_local_refresh_keeps_manual_selections_and_strengths(self):
|
| 101 |
+
ns = namespace("_pick_ui")
|
| 102 |
+
names = ["basic_pick", "scene_pick", "extension_pick", "basic_status", "scene_pick_status",
|
| 103 |
+
"extension_pick_status", "basic_links", "scene_links", "extension_links",
|
| 104 |
+
"basic_shortlist", "manual_repo", "high_strength", "low_strength", "prompt_input"]
|
| 105 |
+
ns.update({name: name for name in names})
|
| 106 |
+
active = {"name": "Existing", "strength": .65, "low_strength": .4}
|
| 107 |
+
state = {"applied": [active], "extra_picks": [{"name": "Manual"}]}
|
| 108 |
+
ns.update(_PICK_OUTPUTS=names,
|
| 109 |
+
_pick_page=lambda *args, **kwargs: ([active, {"name": "New"}], 2, 0, 2),
|
| 110 |
+
_pick_label=lambda i, item: item["name"], _pick_key=lambda item: item["name"],
|
| 111 |
+
_pick_links=lambda page, active: "Local list")
|
| 112 |
+
result = invoke(ns["_pick_ui"], mode="prompt", advance=True, prompt_text="Original",
|
| 113 |
+
space_id=economy.ECONOMY_SPACE, state=state)
|
| 114 |
+
result = dict(zip(names, result))
|
| 115 |
+
self.assertEqual(result["basic_shortlist"]["applied"], state["applied"])
|
| 116 |
+
self.assertEqual(result["basic_shortlist"]["extra_picks"], state["extra_picks"])
|
| 117 |
+
for name in ("manual_repo", "high_strength", "low_strength", "prompt_input"):
|
| 118 |
+
self.assertEqual(result[name], {"__type__": "update"})
|
| 119 |
+
ns["_remote_ask"].assert_not_called()
|
| 120 |
+
|
| 121 |
+
def test_generated_settings_are_rejected_as_text_not_parsed(self):
|
| 122 |
+
for reply in ('{"prompt": "A person", "strength": 1}', 'PICKS: [1]'):
|
| 123 |
+
with self.assertRaises(ValueError):
|
| 124 |
+
economy.economy_prompt(reply, "Original")
|
| 125 |
+
|
| 126 |
+
def test_transport_blocks_catalogues_and_enforces_single_caption_budget(self):
|
| 127 |
+
from PIL import Image
|
| 128 |
+
ns = namespace("_remote_ask")
|
| 129 |
+
client = types.SimpleNamespace(submit=Mock(return_value=types.SimpleNamespace(
|
| 130 |
+
result=lambda **kwargs: "A red coat beside a window.")), close=Mock())
|
| 131 |
+
ns.update(_make_remote_client=Mock(return_value=client),
|
| 132 |
+
prepare_request=lambda writer, message, image: (writer, message, image),
|
| 133 |
+
_remote_plan=Mock(return_value=([((), {"api_name": "/write_prompt"})], [])),
|
| 134 |
+
writer_result=lambda response: response,
|
| 135 |
+
_runtime_event=lambda *args, **kwargs: None, os=os, tempfile=tempfile)
|
| 136 |
+
image = Image.new("RGB", (8, 8))
|
| 137 |
+
with self.assertRaisesRegex(ValueError, "only describes reference images"):
|
| 138 |
+
ns["_remote_ask"](economy.ECONOMY_SPACE, "PICKS: choose adapters", image)
|
| 139 |
+
ns["_make_remote_client"].assert_not_called()
|
| 140 |
+
ns["_remote_ask"](economy.ECONOMY_SPACE, economy.economy_instruction(), image,
|
| 141 |
+
temperature=.9, max_new_tokens=4096)
|
| 142 |
+
client.submit.assert_called_once()
|
| 143 |
+
self.assertEqual(ns["_remote_plan"].call_args.kwargs,
|
| 144 |
+
{"max_new_tokens": 384, "temperature": 0.0})
|
| 145 |
+
client.close.assert_called_once()
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
if __name__ == "__main__":
|
| 149 |
+
unittest.main()
|
tests/test_profiles_and_queue.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""CPU-only regression checks without loading Wan model weights."""
|
| 2 |
import ast
|
| 3 |
import json
|
|
|
|
| 4 |
import os
|
| 5 |
from pathlib import Path
|
| 6 |
import re
|
|
@@ -8,6 +9,7 @@ import tempfile
|
|
| 8 |
import time
|
| 9 |
import types
|
| 10 |
import unittest
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
SOURCE = Path(__file__).resolve().parents[1] / "app.py"
|
|
@@ -31,6 +33,8 @@ def isolated_namespace(directory):
|
|
| 31 |
"gr": types.SimpleNamespace(update=lambda **kwargs: {"__type__": "update", **kwargs}),
|
| 32 |
"os": os, "re": re, "json": json, "time": time, "tempfile": tempfile,
|
| 33 |
"PROFILES_DIR": directory, "NO_PROFILE": "none", "REMOTE_SPACE": "owner/writer",
|
|
|
|
|
|
|
| 34 |
"_scene_count": int, "_runtime_event": lambda *a, **k: None,
|
| 35 |
"FIXED_FPS": 16, "MIN_FRAMES_MODEL": 8, "MAX_FRAMES_MODEL": 321,
|
| 36 |
"MIN_DURATION": 0.5, "MAX_DURATION": 20.1,
|
|
|
|
| 1 |
"""CPU-only regression checks without loading Wan model weights."""
|
| 2 |
import ast
|
| 3 |
import json
|
| 4 |
+
import math
|
| 5 |
import os
|
| 6 |
from pathlib import Path
|
| 7 |
import re
|
|
|
|
| 9 |
import time
|
| 10 |
import types
|
| 11 |
import unittest
|
| 12 |
+
from prompt_assistant import resolve_writer
|
| 13 |
|
| 14 |
|
| 15 |
SOURCE = Path(__file__).resolve().parents[1] / "app.py"
|
|
|
|
| 33 |
"gr": types.SimpleNamespace(update=lambda **kwargs: {"__type__": "update", **kwargs}),
|
| 34 |
"os": os, "re": re, "json": json, "time": time, "tempfile": tempfile,
|
| 35 |
"PROFILES_DIR": directory, "NO_PROFILE": "none", "REMOTE_SPACE": "owner/writer",
|
| 36 |
+
"resolve_writer": resolve_writer,
|
| 37 |
+
"np": types.SimpleNamespace(isfinite=math.isfinite),
|
| 38 |
"_scene_count": int, "_runtime_event": lambda *a, **k: None,
|
| 39 |
"FIXED_FPS": 16, "MIN_FRAMES_MODEL": 8, "MAX_FRAMES_MODEL": 321,
|
| 40 |
"MIN_DURATION": 0.5, "MAX_DURATION": 20.1,
|
tests/test_prompt_assistant.py
CHANGED
|
@@ -43,10 +43,12 @@ class PromptAssistantTests(unittest.TestCase):
|
|
| 43 |
else:
|
| 44 |
result = namespace[name]({"basic_space": "qwen-fable"})[0]["value"]
|
| 45 |
self.assertEqual(result, "owner/current")
|
| 46 |
-
def
|
| 47 |
-
self.assertEqual(len(assistant.assistant_choices("owner/current")),
|
| 48 |
self.assertEqual(assistant.assistant_choices("owner/current")[0][1], "owner/current")
|
| 49 |
self.assertNotIn("fable", assistant.assistant_choices("owner/current")[0][0].lower())
|
|
|
|
|
|
|
| 50 |
|
| 51 |
def test_complete_protocol_and_chat_answers_are_kept_but_partial_output_is_rejected(self):
|
| 52 |
response = {"protocol": "h3-writer-v1", "finish_reason": "stop", "text": "Complete prompt"}
|
|
@@ -77,4 +79,4 @@ class PromptAssistantTests(unittest.TestCase):
|
|
| 77 |
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
-
unittest.main()
|
|
|
|
| 43 |
else:
|
| 44 |
result = namespace[name]({"basic_space": "qwen-fable"})[0]["value"]
|
| 45 |
self.assertEqual(result, "owner/current")
|
| 46 |
+
def test_ui_keeps_current_writer_first_and_adds_optional_economy(self):
|
| 47 |
+
self.assertEqual(len(assistant.assistant_choices("owner/current")), 2)
|
| 48 |
self.assertEqual(assistant.assistant_choices("owner/current")[0][1], "owner/current")
|
| 49 |
self.assertNotIn("fable", assistant.assistant_choices("owner/current")[0][0].lower())
|
| 50 |
+
self.assertEqual(assistant.assistant_choices("owner/current")[1][1],
|
| 51 |
+
"amisima/Qwen3.5-Picture-Captioner")
|
| 52 |
|
| 53 |
def test_complete_protocol_and_chat_answers_are_kept_but_partial_output_is_rejected(self):
|
| 54 |
response = {"protocol": "h3-writer-v1", "finish_reason": "stop", "text": "Complete prompt"}
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
+
unittest.main()
|
tests/test_remote_writer_isolation.py
CHANGED
|
@@ -14,6 +14,29 @@ SOURCE = Path(__file__).resolve().parents[1] / "app.py"
|
|
| 14 |
|
| 15 |
|
| 16 |
class RemoteWriterIsolationTests(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def test_writer_does_not_reuse_a_previous_visitors_quota_header(self):
|
| 18 |
request = contextvars.ContextVar("test_request", default=None)
|
| 19 |
context = types.ModuleType("gradio.context")
|
|
@@ -45,6 +68,7 @@ class RemoteWriterIsolationTests(unittest.TestCase):
|
|
| 45 |
function = next(node for node in tree.body
|
| 46 |
if isinstance(node, ast.FunctionDef) and node.name == "_remote_ask")
|
| 47 |
namespace = {
|
|
|
|
| 48 |
"_REMOTE_CLIENTS": {}, "_make_remote_client": lambda _: OfflineClient(),
|
| 49 |
"prepare_request": lambda writer, message, image: (writer, message, image),
|
| 50 |
"_remote_plan": lambda *args, **kwargs: ([((), {"api_name": "/write_prompt"})], []),
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
class RemoteWriterIsolationTests(unittest.TestCase):
|
| 17 |
+
def test_private_economy_cannot_inherit_the_owner_writer_token(self):
|
| 18 |
+
seen = []
|
| 19 |
+
|
| 20 |
+
class OfflineClient:
|
| 21 |
+
def __init__(self, source, token=None):
|
| 22 |
+
seen.append((source, token))
|
| 23 |
+
|
| 24 |
+
tree = ast.parse(SOURCE.read_text(encoding="utf-8"))
|
| 25 |
+
function = next(node for node in tree.body
|
| 26 |
+
if isinstance(node, ast.FunctionDef) and node.name == "_make_remote_client")
|
| 27 |
+
target = "amisima/Qwen3.5-Picture-Captioner"
|
| 28 |
+
namespace = {
|
| 29 |
+
"os": types.SimpleNamespace(environ={"EXPANDER_HF_TOKEN": "synthetic-owner-only"}),
|
| 30 |
+
"is_economy": lambda writer: writer == target,
|
| 31 |
+
}
|
| 32 |
+
exec(compile(ast.Module([function], type_ignores=[]), str(SOURCE), "exec"), namespace)
|
| 33 |
+
client_module = types.ModuleType("gradio_client")
|
| 34 |
+
client_module.Client = OfflineClient
|
| 35 |
+
with patch.dict(sys.modules, {"gradio_client": client_module}):
|
| 36 |
+
namespace["_make_remote_client"](target)
|
| 37 |
+
namespace["_make_remote_client"]("owner/original-writer")
|
| 38 |
+
self.assertEqual(seen, [(target, False), ("owner/original-writer", "synthetic-owner-only")])
|
| 39 |
+
|
| 40 |
def test_writer_does_not_reuse_a_previous_visitors_quota_header(self):
|
| 41 |
request = contextvars.ContextVar("test_request", default=None)
|
| 42 |
context = types.ModuleType("gradio.context")
|
|
|
|
| 68 |
function = next(node for node in tree.body
|
| 69 |
if isinstance(node, ast.FunctionDef) and node.name == "_remote_ask")
|
| 70 |
namespace = {
|
| 71 |
+
"is_economy": lambda writer: False,
|
| 72 |
"_REMOTE_CLIENTS": {}, "_make_remote_client": lambda _: OfflineClient(),
|
| 73 |
"prepare_request": lambda writer, message, image: (writer, message, image),
|
| 74 |
"_remote_plan": lambda *args, **kwargs: ([((), {"api_name": "/write_prompt"})], []),
|
tests/test_simple_ui.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build the real Gradio components without importing the inference pipeline."""
|
| 2 |
+
import ast
|
| 3 |
+
from collections import Counter
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import unittest
|
| 6 |
+
from unittest.mock import patch
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
import lora_library
|
| 10 |
+
from economy_prompt import ECONOMY_NOTE
|
| 11 |
+
from prompt_assistant import assistant_choices
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
SOURCE = ROOT / "app.py"
|
| 15 |
+
TREE = ast.parse(SOURCE.read_text(encoding="utf-8"))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class UIOnly(ast.NodeTransformer):
|
| 19 |
+
def visit_Expr(self, node):
|
| 20 |
+
# Keep the actual library tab and its event wiring. Its prompt input is
|
| 21 |
+
# constructed with render=False and rendered once later in the workspace.
|
| 22 |
+
call = node.value
|
| 23 |
+
if isinstance(call, ast.Call) and isinstance(call.func, ast.Attribute):
|
| 24 |
+
if call.func.attr in ("click", "change", "input", "submit", "select", "release",
|
| 25 |
+
"blur", "upload", "then", "success", "failure"):
|
| 26 |
+
return None
|
| 27 |
+
return self.generic_visit(node)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def build_ui():
|
| 31 |
+
node = next(n for n in TREE.body if isinstance(n, ast.With) and any(
|
| 32 |
+
isinstance(item.context_expr, ast.Call) and isinstance(item.context_expr.func, ast.Attribute)
|
| 33 |
+
and item.context_expr.func.attr == "Blocks" for item in n.items))
|
| 34 |
+
end = next(i for i, n in enumerate(node.body) if isinstance(n, ast.Assign)
|
| 35 |
+
and any(isinstance(t, ast.Name) and t.id == "ui_inputs" for t in n.targets))
|
| 36 |
+
node = ast.With(items=node.items, body=node.body[:end], type_comment=None)
|
| 37 |
+
module = ast.fix_missing_locations(UIOnly().visit(ast.Module(body=[node], type_ignores=[])))
|
| 38 |
+
ns = {"gr": gr, "assistant_choices": assistant_choices, "ECONOMY_NOTE": ECONOMY_NOTE,
|
| 39 |
+
"REMOTE_SPACE": "amisima/Qwen3.8-27B-Uncensored-Demo", "CSS": "", "HERO": "Feature tour",
|
| 40 |
+
"LORA_MAX_FILE_BYTES": 500 * 1048576, "LORA_MAX_RUN_BYTES": 1000 * 1048576,
|
| 41 |
+
"default_prompt_i2v": "make this image come alive", "default_negative_prompt": "",
|
| 42 |
+
"list_profiles": lambda: [], "NO_PROFILE": "none", "MIN_DURATION": .5,
|
| 43 |
+
"MAX_DURATION": 20.1, "MAX_SCENE_CLIPS": 64, "FIXED_FPS": 16, "MAX_SEED": 2**31-1,
|
| 44 |
+
"STARTER_NONE": "none", "STARTER_RECIPES": {}, "SPEED_NONE": "none", "SPEED_PRESETS": {"none": {}},
|
| 45 |
+
"CAMERA_MOVES": {"(keep as written)": ""}, "FRAMINGS": {"(keep as written)": ""},
|
| 46 |
+
"LIGHTING": {"(keep as written)": ""}, "PACING": {"(keep as written)": ""},
|
| 47 |
+
"PROMPT_CHIPS": [], "LORA_CHOICES": ["(None)"], "SCHEDULER_MAP": {"UniPCMultistep": None},
|
| 48 |
+
"WAN_BASE_MODELS": ["Wan 2.2"], "FOLEY_ENGINES": {"Audio": {}}, "FOLEY_DEFAULT": "Audio",
|
| 49 |
+
"FOLEY_NEGATIVE": "", "lora_library": lora_library}
|
| 50 |
+
with patch.object(lora_library, "load_library", return_value={"normal": [], "nsfw": []}):
|
| 51 |
+
exec(compile(module, str(SOURCE), "exec"), ns)
|
| 52 |
+
return ns
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class SimpleUITests(unittest.TestCase):
|
| 56 |
+
@classmethod
|
| 57 |
+
def setUpClass(cls):
|
| 58 |
+
cls.ns = build_ui()
|
| 59 |
+
cls.config = cls.ns["demo"].config
|
| 60 |
+
|
| 61 |
+
@classmethod
|
| 62 |
+
def tearDownClass(cls):
|
| 63 |
+
cls.ns["demo"].close()
|
| 64 |
+
|
| 65 |
+
def test_single_collapsed_settings_and_same_essential_instances(self):
|
| 66 |
+
ns = self.ns
|
| 67 |
+
self.assertFalse(ns["more_settings"].open)
|
| 68 |
+
top = self.config["layout"]["children"]
|
| 69 |
+
self.assertEqual(sum(n["id"] == ns["more_settings"]._id for n in top), 1)
|
| 70 |
+
workspace = next(n for n in top if n["id"] == ns["simple_workspace"]._id)
|
| 71 |
+
settings = next(n for n in top if n["id"] == ns["more_settings"]._id)
|
| 72 |
+
def ids(node):
|
| 73 |
+
return [node["id"]] + [i for c in node.get("children", []) for i in ids(c)]
|
| 74 |
+
all_ids = ids(self.config["layout"])
|
| 75 |
+
self.assertFalse([i for i, count in Counter(all_ids).items() if count > 1])
|
| 76 |
+
essential = ("input_image_component", "prompt_input", "duration_seconds_input",
|
| 77 |
+
"generate_button", "video_output", "file_output", "status_box")
|
| 78 |
+
for name in essential:
|
| 79 |
+
self.assertIn(ns[name]._id, ids(workspace), name)
|
| 80 |
+
self.assertNotIn(ns[name]._id, ids(settings), name)
|
| 81 |
+
self.assertEqual(all_ids.count(ns[name]._id), 1, name)
|
| 82 |
+
for name in ("pb_space", "basic_btn", "simple_lora", "lora1_high_scale", "my5_ls",
|
| 83 |
+
"profile_picker", "sound_prompt", "identity_strength_slider", "extension_prompt",
|
| 84 |
+
"scene_idea", "gpu_estimate", "safe_mode_checkbox"):
|
| 85 |
+
self.assertIn(ns[name]._id, ids(settings), name)
|
| 86 |
+
self.assertNotIn(ns[name]._id, ids(workspace), name)
|
| 87 |
+
self.assertFalse(ns["studio_tour"].visible)
|
| 88 |
+
|
| 89 |
+
def test_defaults_and_generation_event_keep_existing_components(self):
|
| 90 |
+
ns = self.ns
|
| 91 |
+
self.assertEqual(ns["pb_space"].value, "amisima/Qwen3.8-27B-Uncensored-Demo")
|
| 92 |
+
self.assertEqual(ns["generate_button"].value, "Generate")
|
| 93 |
+
self.assertEqual(ns["duration_seconds_input"].value, 3.5)
|
| 94 |
+
self.assertEqual(ns["steps_slider"].value, 6)
|
| 95 |
+
self.assertTrue(ns["prompt_input"].value)
|
| 96 |
+
ui_inputs = next(n.value for n in ast.walk(TREE) if isinstance(n, ast.Assign)
|
| 97 |
+
and any(isinstance(t, ast.Name) and t.id == "ui_inputs" for t in n.targets))
|
| 98 |
+
self.assertEqual([n.id for n in ui_inputs.elts[:3]],
|
| 99 |
+
["input_image_component", "last_image_component", "prompt_input"])
|
| 100 |
+
self.assertEqual(len(ns["pb_space"].choices), 2)
|
| 101 |
+
self.assertIn("private test", ns["pb_space"].choices[1][0])
|
| 102 |
+
|
| 103 |
+
def test_library_callbacks_use_the_same_prompt_before_it_is_rendered(self):
|
| 104 |
+
prompt_id = self.ns["prompt_input"]._id
|
| 105 |
+
dependencies = self.config["dependencies"]
|
| 106 |
+
self.assertTrue(any(prompt_id in event["inputs"] for event in dependencies))
|
| 107 |
+
self.assertTrue(any(prompt_id in event["outputs"] for event in dependencies))
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
unittest.main()
|