Spaces:
Running on Zero
fix: after a run every mode's sample can still be seen: while the monitor holds a run of another mode than the selected one, the button under the purpose line reads "See an example of <mode>" at every width (class mr-over-run), puts that sample on the monitor and lets later switches follow with their own, and reads "Back to your run" while a sample covers the run (#20)
Browse filesRound 4's M4: after one successful run no mode's sample could be seen again in
the session. The monitor rightly kept the run when the mode changed (AC-06), the
jump to the sample showed only while the monitor held a sample, and it was hidden
at 1024 px and wider; a reload was the only way back, and it emptied Recent runs.
The monitor state of a run now carries its mode, seed, files and whether it is an
earlier run (Show). The button under the purpose line is decided from the selected
mode and that state in one place (_jump_update): over a run of another mode whose
mode has a sample it reads "See an example of Audio to audio" with the class
mr-over-run (UI-A's stylesheet shows it on a desktop with that class); while a
sample covers a run it reads "Back to your run", as long as the run's file is on
disk; while the monitor shows a sample with no run under it, it is the phone's
plain jump. A click puts the sample on the monitor with its usual caption and sets
the state to "sample" with the run kept, so later switches show their own samples;
"Back to your run" puts the run back under its own caption ("Your run." or
"Earlier run."). Below 1024 px the click still scrolls to the monitor; wider, the
rail scrolls as little as it takes, as for Show.
Found on the way: a run that finished while another mode was selected was captioned,
listed in Recent runs and kept in the monitor state under the selected mode, so
Restore brought back the wrong mode. The finish step now names a finished run by
its own mode; the review still uses the selected one.
Tests (tests/test_ui_sample_over_run.py, through the built page's own steps and a
real run with the GPU seams faked): run, switch to Audio to audio, the example,
a switch to Audio to video, back to the run; an earlier run shown from Recent runs;
a mode with no sample; an evicted run; a new run; the click through Gradio's own
process_api; the scroll script. The form harness now tracks elem_classes.
- docs/UI_DESIGN.md +12 -3
- ltx25_studio/ui/blocks.py +134 -22
- ltx25_studio/ui/render.py +10 -0
- tests/test_ui_form.py +1 -1
- tests/test_ui_sample_over_run.py +271 -0
|
@@ -57,7 +57,8 @@ same Generate button, restyled. There is never a second Generate in the DOM. Pre
|
|
| 57 |
Generate or Show on a narrow screen scrolls the monitor into view; Restore settings
|
| 58 |
brings the purpose line, which names the restored mode, into view; and while the
|
| 59 |
monitor shows a sample a "See an example output" button under the purpose line jumps
|
| 60 |
-
to it.
|
|
|
|
| 61 |
|
| 62 |
## The matrix
|
| 63 |
|
|
@@ -151,9 +152,17 @@ exported, so joint modes never show one file twice. Its contents depend on the s
|
|
| 151 |
- **Idle:** the selected mode's sample output from the manifest, captioned "Example
|
| 152 |
output, not your run". If there is no sample, a designed idle frame names the mode.
|
| 153 |
- **During a run:** the phase-labelled progress (`show_progress_on`).
|
| 154 |
-
- **After a run:** that run's result, captioned with its mode
|
| 155 |
-
|
|
|
|
| 156 |
- **Shown from Recent runs:** an earlier run's own file, captioned "Earlier run".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
**The cost panel** is the signature element. It is a labelled grid with these rows:
|
| 159 |
|
|
|
|
| 57 |
Generate or Show on a narrow screen scrolls the monitor into view; Restore settings
|
| 58 |
brings the purpose line, which names the restored mode, into view; and while the
|
| 59 |
monitor shows a sample a "See an example output" button under the purpose line jumps
|
| 60 |
+
to it. The same button, at every width, offers the selected mode's sample over a run
|
| 61 |
+
of another mode (see the monitor, below).
|
| 62 |
|
| 63 |
## The matrix
|
| 64 |
|
|
|
|
| 152 |
- **Idle:** the selected mode's sample output from the manifest, captioned "Example
|
| 153 |
output, not your run". If there is no sample, a designed idle frame names the mode.
|
| 154 |
- **During a run:** the phase-labelled progress (`show_progress_on`).
|
| 155 |
+
- **After a run:** that run's result, captioned with its own mode (the one that ran,
|
| 156 |
+
even if another was selected while it ran) and seed. It stays on screen when the
|
| 157 |
+
mode changes.
|
| 158 |
- **Shown from Recent runs:** an earlier run's own file, captioned "Earlier run".
|
| 159 |
+
- **A sample over a run:** while the monitor holds a run (yours or an earlier one) of
|
| 160 |
+
another mode than the selected one, and that mode has a sample, the button under the
|
| 161 |
+
purpose line reads "See an example of Audio to audio" at every width (class
|
| 162 |
+
`mr-over-run`). It puts that sample on the monitor with its usual caption, and later
|
| 163 |
+
switches follow with their own samples; the run is kept, and the same button reads
|
| 164 |
+
"Back to your run" and puts it back, while its file is still on disk. Below 1024 px
|
| 165 |
+
the button also scrolls to the monitor.
|
| 166 |
|
| 167 |
**The cost panel** is the signature element. It is a labelled grid with these rows:
|
| 168 |
|
|
@@ -901,7 +901,7 @@ def build_ui() -> gr.Blocks:
|
|
| 901 |
*example_updates,
|
| 902 |
*monitor_updates,
|
| 903 |
monitor_next,
|
| 904 |
-
|
| 905 |
status_update,
|
| 906 |
failure,
|
| 907 |
]
|
|
@@ -1333,7 +1333,8 @@ def build_ui() -> gr.Blocks:
|
|
| 1333 |
run whose result goes on the monitor; without one the monitor is idle and
|
| 1334 |
holds no file, and ``report`` is the card the status holds. ``listed`` is a
|
| 1335 |
finished run that is not shown: it goes into Recent runs, where Show can serve
|
| 1336 |
-
its file.
|
|
|
|
| 1337 |
mode = modes.get_mode(mode_id)
|
| 1338 |
review_out = _review(mode_id, False, source, *values)
|
| 1339 |
entries = list(recent_now or [])
|
|
@@ -1341,7 +1342,11 @@ def build_ui() -> gr.Blocks:
|
|
| 1341 |
entries.insert(
|
| 1342 |
0,
|
| 1343 |
_recent_entry(
|
| 1344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1345 |
),
|
| 1346 |
)
|
| 1347 |
entries = entries[:RECENT_LIMIT]
|
|
@@ -1349,14 +1354,16 @@ def build_ui() -> gr.Blocks:
|
|
| 1349 |
result = shown.result
|
| 1350 |
params = shown.params
|
| 1351 |
facts = handlers.run_facts(shown)
|
| 1352 |
-
entries.insert(0, _recent_entry(mode_id, result, params, facts, shown))
|
| 1353 |
entries = entries[:RECENT_LIMIT]
|
| 1354 |
has_video = shown.video is not None
|
| 1355 |
monitor = [
|
| 1356 |
gr.update(visible=False),
|
| 1357 |
gr.update(value=shown.video, visible=has_video, autoplay=True),
|
| 1358 |
gr.update(value=shown.audio if not has_video else None, visible=not has_video),
|
| 1359 |
-
render.monitor_caption(
|
|
|
|
|
|
|
| 1360 |
]
|
| 1361 |
summary = gr.update(value=render.run_summary(facts), visible=True)
|
| 1362 |
seed_button = gr.update(value="Reuse seed", visible=True)
|
|
@@ -1365,7 +1372,7 @@ def build_ui() -> gr.Blocks:
|
|
| 1365 |
differs = bool(sent) and sent.strip() != str(params.get("prompt") or "").strip()
|
| 1366 |
prompt_button = gr.update(visible=differs)
|
| 1367 |
prompt_value = sent if differs else None
|
| 1368 |
-
monitor_next =
|
| 1369 |
failure = None
|
| 1370 |
else:
|
| 1371 |
monitor = [
|
|
@@ -1403,7 +1410,7 @@ def build_ui() -> gr.Blocks:
|
|
| 1403 |
gr.update(visible=bool(entries)),
|
| 1404 |
*_recent_rows(entries),
|
| 1405 |
status_update,
|
| 1406 |
-
|
| 1407 |
failure,
|
| 1408 |
]
|
| 1409 |
|
|
@@ -1531,7 +1538,7 @@ def build_ui() -> gr.Blocks:
|
|
| 1531 |
|
| 1532 |
show_outputs = [monitor_idle, video_out, audio_out, monitor_caption, monitor_state]
|
| 1533 |
|
| 1534 |
-
def _show(index: int, entries: list, monitor: dict) -> list[Any]:
|
| 1535 |
entries = list(entries or [])
|
| 1536 |
entry = entries[index] if index < len(entries) else None
|
| 1537 |
path = entry and (entry.get("video") or entry.get("audio"))
|
|
@@ -1546,29 +1553,36 @@ def build_ui() -> gr.Blocks:
|
|
| 1546 |
gr.update(visible=False),
|
| 1547 |
gr.update(),
|
| 1548 |
]
|
| 1549 |
-
|
| 1550 |
-
|
|
|
|
| 1551 |
return [
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
gr.update(value=None if has_video else entry.get("audio"), visible=not has_video),
|
| 1555 |
-
render.monitor_caption(kind="earlier", mode=mode, seed=entry["seed"]),
|
| 1556 |
-
{"kind": "run", "mode": entry["mode"]},
|
| 1557 |
gr.update(),
|
| 1558 |
-
|
| 1559 |
]
|
| 1560 |
|
| 1561 |
for index, row in enumerate(recent_rows):
|
| 1562 |
show_run = row[1]
|
| 1563 |
show_run.click(
|
| 1564 |
-
fn=lambda entries, monitor, i=index: _show(i, entries, monitor),
|
| 1565 |
-
inputs=[recent, monitor_state],
|
| 1566 |
outputs=[*show_outputs, show_run, sample_jump],
|
| 1567 |
js=_SCROLL_TO_MONITOR,
|
| 1568 |
**_PRIVATE,
|
| 1569 |
)
|
| 1570 |
|
| 1571 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1572 |
|
| 1573 |
# =================================================================
|
| 1574 |
# examples: fill the form, run nothing
|
|
@@ -1611,10 +1625,16 @@ def build_ui() -> gr.Blocks:
|
|
| 1611 |
# helpers for build_ui
|
| 1612 |
# ---------------------------------------------------------------------------
|
| 1613 |
|
|
|
|
|
|
|
| 1614 |
_SCROLL_TO_SAMPLE = """
|
| 1615 |
-
() => {
|
| 1616 |
const still = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
| 1617 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1618 |
}
|
| 1619 |
"""
|
| 1620 |
|
|
@@ -1754,10 +1774,19 @@ def _sample_caption(mode: Any, sample: showcase.Sample | None) -> str:
|
|
| 1754 |
|
| 1755 |
def _monitor_for_mode(show: showcase.Showcase, mode: Any, monitor: dict) -> tuple[list, dict]:
|
| 1756 |
"""Swap the idle monitor to the new mode's sample; never hide a finished run. A failed
|
| 1757 |
-
run's caption stays only in its own mode: elsewhere its card is one line naming it.
|
|
|
|
| 1758 |
kind = (monitor or {}).get("kind")
|
| 1759 |
if kind in ("run", "running") or (kind == "failed" and monitor.get("mode") == mode.id):
|
| 1760 |
return [gr.update(), gr.update(), gr.update(), gr.update()], monitor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1761 |
sample = show.sample_for(mode.id)
|
| 1762 |
if sample is None:
|
| 1763 |
return (
|
|
@@ -1786,6 +1815,89 @@ def _monitor_for_mode(show: showcase.Showcase, mode: Any, monitor: dict) -> tupl
|
|
| 1786 |
)
|
| 1787 |
|
| 1788 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1789 |
def _example_updates(show: showcase.Showcase, mode_id: str, slots: int, note: Any) -> list:
|
| 1790 |
if not slots:
|
| 1791 |
return []
|
|
|
|
| 901 |
*example_updates,
|
| 902 |
*monitor_updates,
|
| 903 |
monitor_next,
|
| 904 |
+
_jump_update(show, mode_id, monitor_next),
|
| 905 |
status_update,
|
| 906 |
failure,
|
| 907 |
]
|
|
|
|
| 1333 |
run whose result goes on the monitor; without one the monitor is idle and
|
| 1334 |
holds no file, and ``report`` is the card the status holds. ``listed`` is a
|
| 1335 |
finished run that is not shown: it goes into Recent runs, where Show can serve
|
| 1336 |
+
its file. ``mode_id`` is the selected mode (the review's); a finished run is
|
| 1337 |
+
named by its own mode, which the user may have left while it ran."""
|
| 1338 |
mode = modes.get_mode(mode_id)
|
| 1339 |
review_out = _review(mode_id, False, source, *values)
|
| 1340 |
entries = list(recent_now or [])
|
|
|
|
| 1342 |
entries.insert(
|
| 1343 |
0,
|
| 1344 |
_recent_entry(
|
| 1345 |
+
listed.mode_id,
|
| 1346 |
+
listed.result,
|
| 1347 |
+
listed.params,
|
| 1348 |
+
handlers.run_facts(listed),
|
| 1349 |
+
listed,
|
| 1350 |
),
|
| 1351 |
)
|
| 1352 |
entries = entries[:RECENT_LIMIT]
|
|
|
|
| 1354 |
result = shown.result
|
| 1355 |
params = shown.params
|
| 1356 |
facts = handlers.run_facts(shown)
|
| 1357 |
+
entries.insert(0, _recent_entry(shown.mode_id, result, params, facts, shown))
|
| 1358 |
entries = entries[:RECENT_LIMIT]
|
| 1359 |
has_video = shown.video is not None
|
| 1360 |
monitor = [
|
| 1361 |
gr.update(visible=False),
|
| 1362 |
gr.update(value=shown.video, visible=has_video, autoplay=True),
|
| 1363 |
gr.update(value=shown.audio if not has_video else None, visible=not has_video),
|
| 1364 |
+
render.monitor_caption(
|
| 1365 |
+
kind="run", mode=modes.get_mode(shown.mode_id), seed=result.seed
|
| 1366 |
+
),
|
| 1367 |
]
|
| 1368 |
summary = gr.update(value=render.run_summary(facts), visible=True)
|
| 1369 |
seed_button = gr.update(value="Reuse seed", visible=True)
|
|
|
|
| 1372 |
differs = bool(sent) and sent.strip() != str(params.get("prompt") or "").strip()
|
| 1373 |
prompt_button = gr.update(visible=differs)
|
| 1374 |
prompt_value = sent if differs else None
|
| 1375 |
+
monitor_next = _run_state(shown.mode_id, result.seed, shown.video, shown.audio)
|
| 1376 |
failure = None
|
| 1377 |
else:
|
| 1378 |
monitor = [
|
|
|
|
| 1410 |
gr.update(visible=bool(entries)),
|
| 1411 |
*_recent_rows(entries),
|
| 1412 |
status_update,
|
| 1413 |
+
_jump_update(show, mode_id, monitor_next),
|
| 1414 |
failure,
|
| 1415 |
]
|
| 1416 |
|
|
|
|
| 1538 |
|
| 1539 |
show_outputs = [monitor_idle, video_out, audio_out, monitor_caption, monitor_state]
|
| 1540 |
|
| 1541 |
+
def _show(index: int, entries: list, monitor: dict, mode_id: str) -> list[Any]:
|
| 1542 |
entries = list(entries or [])
|
| 1543 |
entry = entries[index] if index < len(entries) else None
|
| 1544 |
path = entry and (entry.get("video") or entry.get("audio"))
|
|
|
|
| 1553 |
gr.update(visible=False),
|
| 1554 |
gr.update(),
|
| 1555 |
]
|
| 1556 |
+
state = _run_state(
|
| 1557 |
+
entry["mode"], entry["seed"], entry.get("video"), entry.get("audio"), earlier=True
|
| 1558 |
+
)
|
| 1559 |
return [
|
| 1560 |
+
*_run_on_monitor(state),
|
| 1561 |
+
state,
|
|
|
|
|
|
|
|
|
|
| 1562 |
gr.update(),
|
| 1563 |
+
_jump_update(show, mode_id, state),
|
| 1564 |
]
|
| 1565 |
|
| 1566 |
for index, row in enumerate(recent_rows):
|
| 1567 |
show_run = row[1]
|
| 1568 |
show_run.click(
|
| 1569 |
+
fn=lambda entries, monitor, mode_id, i=index: _show(i, entries, monitor, mode_id),
|
| 1570 |
+
inputs=[recent, monitor_state, mode_selector],
|
| 1571 |
outputs=[*show_outputs, show_run, sample_jump],
|
| 1572 |
js=_SCROLL_TO_MONITOR,
|
| 1573 |
**_PRIVATE,
|
| 1574 |
)
|
| 1575 |
|
| 1576 |
+
def _on_jump(mode_id: str, monitor: dict) -> list[Any]:
|
| 1577 |
+
return _jump(show, mode_id, monitor)
|
| 1578 |
+
|
| 1579 |
+
sample_jump.click(
|
| 1580 |
+
fn=_on_jump,
|
| 1581 |
+
inputs=[mode_selector, monitor_state],
|
| 1582 |
+
outputs=[*show_outputs, sample_jump],
|
| 1583 |
+
js=_SCROLL_TO_SAMPLE,
|
| 1584 |
+
**_PRIVATE,
|
| 1585 |
+
)
|
| 1586 |
|
| 1587 |
# =================================================================
|
| 1588 |
# examples: fill the form, run nothing
|
|
|
|
| 1625 |
# helpers for build_ui
|
| 1626 |
# ---------------------------------------------------------------------------
|
| 1627 |
|
| 1628 |
+
#: The control under the purpose line shows or changes the monitor: below 1024 px the page
|
| 1629 |
+
#: brings it in (it sits under the inputs); wider, the rail scrolls as little as it takes.
|
| 1630 |
_SCROLL_TO_SAMPLE = """
|
| 1631 |
+
(...args) => {
|
| 1632 |
const still = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
| 1633 |
+
const wide = window.innerWidth >= 1024;
|
| 1634 |
+
document.getElementById('monitor')?.scrollIntoView(wide
|
| 1635 |
+
? {behavior: 'instant', block: 'nearest'}
|
| 1636 |
+
: {behavior: still ? 'auto' : 'smooth', block: 'center'});
|
| 1637 |
+
return args;
|
| 1638 |
}
|
| 1639 |
"""
|
| 1640 |
|
|
|
|
| 1774 |
|
| 1775 |
def _monitor_for_mode(show: showcase.Showcase, mode: Any, monitor: dict) -> tuple[list, dict]:
|
| 1776 |
"""Swap the idle monitor to the new mode's sample; never hide a finished run. A failed
|
| 1777 |
+
run's caption stays only in its own mode: elsewhere its card is one line naming it. A
|
| 1778 |
+
sample put over a run keeps that run to go back to."""
|
| 1779 |
kind = (monitor or {}).get("kind")
|
| 1780 |
if kind in ("run", "running") or (kind == "failed" and monitor.get("mode") == mode.id):
|
| 1781 |
return [gr.update(), gr.update(), gr.update(), gr.update()], monitor
|
| 1782 |
+
updates, state = _sample_on_monitor(show, mode)
|
| 1783 |
+
if (monitor or {}).get("covered"):
|
| 1784 |
+
state["covered"] = monitor["covered"]
|
| 1785 |
+
return updates, state
|
| 1786 |
+
|
| 1787 |
+
|
| 1788 |
+
def _sample_on_monitor(show: showcase.Showcase, mode: Any) -> tuple[list, dict]:
|
| 1789 |
+
"""The monitor showing ``mode``'s sample with its caption, or its idle frame."""
|
| 1790 |
sample = show.sample_for(mode.id)
|
| 1791 |
if sample is None:
|
| 1792 |
return (
|
|
|
|
| 1815 |
)
|
| 1816 |
|
| 1817 |
|
| 1818 |
+
#: The control under the purpose line is a quiet button; with this class the stylesheet
|
| 1819 |
+
#: shows it at every width (``chrome.py``), not only where the monitor sits under the form.
|
| 1820 |
+
_QUIET = "mr-quiet"
|
| 1821 |
+
_OVER_RUN = "mr-over-run"
|
| 1822 |
+
|
| 1823 |
+
|
| 1824 |
+
def _run_state(mode_id: str, seed: Any, video: Any, audio: Any, *, earlier: bool = False) -> dict:
|
| 1825 |
+
"""The monitor state of a run on it: what it is and enough to put it back."""
|
| 1826 |
+
return {
|
| 1827 |
+
"kind": "run",
|
| 1828 |
+
"mode": mode_id,
|
| 1829 |
+
"seed": int(seed),
|
| 1830 |
+
"video": video,
|
| 1831 |
+
"audio": audio,
|
| 1832 |
+
"earlier": earlier,
|
| 1833 |
+
}
|
| 1834 |
+
|
| 1835 |
+
|
| 1836 |
+
def _kept(state: dict | None) -> bool:
|
| 1837 |
+
"""Whether a run's file is still on disk (its folder may have been evicted)."""
|
| 1838 |
+
path = (state or {}).get("video") or (state or {}).get("audio")
|
| 1839 |
+
return bool(path) and Path(path).exists()
|
| 1840 |
+
|
| 1841 |
+
|
| 1842 |
+
def _run_on_monitor(state: dict) -> list:
|
| 1843 |
+
"""The monitor showing the run ``state`` describes, under its own caption."""
|
| 1844 |
+
mode = modes.get_mode(state["mode"])
|
| 1845 |
+
has_video = state.get("video") is not None
|
| 1846 |
+
return [
|
| 1847 |
+
gr.update(visible=False),
|
| 1848 |
+
gr.update(value=state.get("video"), visible=has_video, autoplay=False),
|
| 1849 |
+
gr.update(value=None if has_video else state.get("audio"), visible=not has_video),
|
| 1850 |
+
render.monitor_caption(
|
| 1851 |
+
kind="earlier" if state.get("earlier") else "run", mode=mode, seed=state.get("seed")
|
| 1852 |
+
),
|
| 1853 |
+
]
|
| 1854 |
+
|
| 1855 |
+
|
| 1856 |
+
def _over_run(show: showcase.Showcase, mode_id: str, monitor: dict) -> bool:
|
| 1857 |
+
"""The monitor holds a run of another mode than ``mode_id``, which has a sample."""
|
| 1858 |
+
return (
|
| 1859 |
+
monitor.get("kind") == "run"
|
| 1860 |
+
and monitor.get("mode") != mode_id
|
| 1861 |
+
and show.sample_for(mode_id) is not None
|
| 1862 |
+
)
|
| 1863 |
+
|
| 1864 |
+
|
| 1865 |
+
def _jump_update(show: showcase.Showcase, mode_id: str, monitor: dict | None) -> dict:
|
| 1866 |
+
"""The control under the purpose line, for the selected mode and what the monitor holds.
|
| 1867 |
+
|
| 1868 |
+
Over a run of another mode: that mode's sample, at every width. While a sample covers a
|
| 1869 |
+
run: the way back. While the monitor shows the mode's sample: the jump to it, which the
|
| 1870 |
+
stylesheet shows only where the monitor sits under the form.
|
| 1871 |
+
"""
|
| 1872 |
+
monitor = monitor or {}
|
| 1873 |
+
if _over_run(show, mode_id, monitor):
|
| 1874 |
+
words, classes = render.sample_of(modes.get_mode(mode_id)), [_QUIET, _OVER_RUN]
|
| 1875 |
+
elif _kept(monitor.get("covered")):
|
| 1876 |
+
words, classes = render.BACK_TO_RUN, [_QUIET, _OVER_RUN]
|
| 1877 |
+
elif monitor.get("kind") == "sample":
|
| 1878 |
+
words, classes = render.SAMPLE_JUMP, [_QUIET]
|
| 1879 |
+
else:
|
| 1880 |
+
return gr.update(value=render.SAMPLE_JUMP, visible=False, elem_classes=[_QUIET])
|
| 1881 |
+
return gr.update(value=words, visible=True, elem_classes=classes)
|
| 1882 |
+
|
| 1883 |
+
|
| 1884 |
+
def _jump(show: showcase.Showcase, mode_id: str, monitor: dict | None) -> list:
|
| 1885 |
+
"""The control under the purpose line, pressed. Over a run of another mode, that mode's
|
| 1886 |
+
sample goes on the monitor and later switches follow with their own; while a sample
|
| 1887 |
+
covers a run, the run comes back. Otherwise (the jump to the sample) only the page moves.
|
| 1888 |
+
Returns the monitor's four outputs, its state and the control."""
|
| 1889 |
+
monitor = dict(monitor or {})
|
| 1890 |
+
if _over_run(show, mode_id, monitor):
|
| 1891 |
+
updates, state = _sample_on_monitor(show, modes.get_mode(mode_id))
|
| 1892 |
+
state["covered"] = monitor
|
| 1893 |
+
elif _kept(monitor.get("covered")):
|
| 1894 |
+
state = dict(monitor["covered"])
|
| 1895 |
+
updates = _run_on_monitor(state)
|
| 1896 |
+
else:
|
| 1897 |
+
updates, state = [gr.update(), gr.update(), gr.update(), gr.update()], monitor
|
| 1898 |
+
return [*updates, state, _jump_update(show, mode_id, state)]
|
| 1899 |
+
|
| 1900 |
+
|
| 1901 |
def _example_updates(show: showcase.Showcase, mode_id: str, slots: int, note: Any) -> list:
|
| 1902 |
if not slots:
|
| 1903 |
return []
|
|
@@ -87,6 +87,7 @@ __all__ = [
|
|
| 87 |
"result_not_shown",
|
| 88 |
"run_summary",
|
| 89 |
"running",
|
|
|
|
| 90 |
"shot_anchor_readout",
|
| 91 |
"success",
|
| 92 |
"upscale_info",
|
|
@@ -833,6 +834,15 @@ READY = "Ready. Nothing is spent until you press Generate."
|
|
| 833 |
|
| 834 |
#: Below 1024 px the monitor sits under the inputs: a jump to the mode's sample.
|
| 835 |
SAMPLE_JUMP = "See an example output"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
|
| 837 |
|
| 838 |
def monitor_idle(mode: Any) -> str:
|
|
|
|
| 87 |
"result_not_shown",
|
| 88 |
"run_summary",
|
| 89 |
"running",
|
| 90 |
+
"sample_of",
|
| 91 |
"shot_anchor_readout",
|
| 92 |
"success",
|
| 93 |
"upscale_info",
|
|
|
|
| 834 |
|
| 835 |
#: Below 1024 px the monitor sits under the inputs: a jump to the mode's sample.
|
| 836 |
SAMPLE_JUMP = "See an example output"
|
| 837 |
+
#: While the monitor holds a run from another mode, at every width: the selected mode's sample.
|
| 838 |
+
SAMPLE_OF = "See an example of {mode}"
|
| 839 |
+
#: While a sample covers a run, the same control puts the run back.
|
| 840 |
+
BACK_TO_RUN = "Back to your run"
|
| 841 |
+
|
| 842 |
+
|
| 843 |
+
def sample_of(mode: Any) -> str:
|
| 844 |
+
"""The control that puts ``mode``'s sample on a monitor holding a run of another mode."""
|
| 845 |
+
return SAMPLE_OF.format(mode=mode.label)
|
| 846 |
|
| 847 |
|
| 848 |
def monitor_idle(mode: Any) -> str:
|
|
@@ -20,7 +20,7 @@ from ltx25_studio.ui.fields import FIELD_KEYS
|
|
| 20 |
|
| 21 |
gr = pytest.importorskip("gradio", reason="gradio is a declared dev dependency")
|
| 22 |
|
| 23 |
-
_PROPS = ("visible", "interactive", "label", "info", "placeholder", "choices")
|
| 24 |
|
| 25 |
|
| 26 |
def _same(a: Any, b: Any) -> bool:
|
|
|
|
| 20 |
|
| 21 |
gr = pytest.importorskip("gradio", reason="gradio is a declared dev dependency")
|
| 22 |
|
| 23 |
+
_PROPS = ("visible", "interactive", "label", "info", "placeholder", "choices", "elem_classes")
|
| 24 |
|
| 25 |
|
| 26 |
def _same(a: Any, b: Any) -> bool:
|
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A run stays on the monitor, and every mode's sample can still be seen (review round 4, M4).
|
| 2 |
+
|
| 3 |
+
After one successful run no mode's sample could be seen again in the session: the monitor kept
|
| 4 |
+
the run when the mode changed (AC-06, right), and the jump to the sample showed only while the
|
| 5 |
+
monitor held a sample. Now, while the monitor holds a run (yours or an earlier one) from another
|
| 6 |
+
mode than the selected one, and that mode has a sample, the control under the purpose line reads
|
| 7 |
+
"See an example of <mode>" at every width (class ``mr-over-run``, which the stylesheet shows on a
|
| 8 |
+
desktop); a click puts that sample on the monitor with its usual caption and the monitor follows
|
| 9 |
+
later switches with their own samples; while a sample covers the run the same control reads
|
| 10 |
+
"Back to your run" and puts it back.
|
| 11 |
+
|
| 12 |
+
Driven through the built page's own steps (:class:`test_ui_form.Form`): a real run through
|
| 13 |
+
``handlers.run`` (GPU seams faked), the real finish step, the real switch and the real click.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
|
| 20 |
+
import pytest
|
| 21 |
+
from conftest import inputs_for
|
| 22 |
+
from test_exports_contract import FakePipe, factory_returning, one_muxed_file_encoder
|
| 23 |
+
from test_ui_form import Form
|
| 24 |
+
|
| 25 |
+
from ltx25_studio import generate as generate_module
|
| 26 |
+
from ltx25_studio import modes
|
| 27 |
+
from ltx25_studio.ui import blocks, handlers, render, showcase
|
| 28 |
+
from ltx25_studio.ui.fields import FIELD_KEYS, FIELDS
|
| 29 |
+
|
| 30 |
+
gr = pytest.importorskip("gradio", reason="gradio is a declared dev dependency")
|
| 31 |
+
|
| 32 |
+
#: The modes the stand-in manifest has samples for: the run's own (05), a sound-only one (10)
|
| 33 |
+
#: and Audio to video (11). Text to video (01) has none.
|
| 34 |
+
SAMPLES = {
|
| 35 |
+
"text_to_audio_video": "samples/t2av.mp4",
|
| 36 |
+
"audio_to_audio": "samples/a2a.m4a",
|
| 37 |
+
"audio_to_video": "samples/a2v.mp4",
|
| 38 |
+
}
|
| 39 |
+
OVER_RUN = "mr-over-run"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Request:
|
| 43 |
+
session_hash = "sample-over-run"
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@pytest.fixture
|
| 47 |
+
def show_dir(tmp_path, monkeypatch):
|
| 48 |
+
root = tmp_path / "examples"
|
| 49 |
+
(root / "samples").mkdir(parents=True)
|
| 50 |
+
entries = {}
|
| 51 |
+
for mode_id, relative in SAMPLES.items():
|
| 52 |
+
(root / relative).write_bytes(b"sample")
|
| 53 |
+
entries[mode_id] = {"sample": {"file": relative, "caption": "Made earlier.", "seed": 3}}
|
| 54 |
+
(root / showcase.MANIFEST).write_text(json.dumps({"modes": entries}), encoding="utf-8")
|
| 55 |
+
monkeypatch.setenv(showcase.EXAMPLES_ENV, str(root))
|
| 56 |
+
return root
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@pytest.fixture
|
| 60 |
+
def form(show_dir):
|
| 61 |
+
return Form(blocks.build_ui())
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@pytest.fixture
|
| 65 |
+
def wired(tmp_path, monkeypatch):
|
| 66 |
+
real = generate_module.generate
|
| 67 |
+
monkeypatch.setattr(
|
| 68 |
+
generate_module,
|
| 69 |
+
"generate",
|
| 70 |
+
lambda **params: real(
|
| 71 |
+
pipeline_factory=factory_returning(FakePipe()),
|
| 72 |
+
encoder=one_muxed_file_encoder,
|
| 73 |
+
output_root=tmp_path / "runs",
|
| 74 |
+
retention_bytes=10**9,
|
| 75 |
+
**params,
|
| 76 |
+
),
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def a_run(form: Form, mode_id: str = "text_to_audio_video") -> handlers.RunOutcome:
|
| 81 |
+
"""A run of ``mode_id`` through the real handler, then the page's real finish step."""
|
| 82 |
+
values = {spec.key: spec.default for spec in FIELDS} | inputs_for(mode_id) | {"seed": 5}
|
| 83 |
+
outcome = handlers.run(mode_id, *(values[k] for k in FIELD_KEYS))
|
| 84 |
+
assert outcome.error is None and outcome.video, outcome.status
|
| 85 |
+
form.values[form.by_id("run-status")._id] = outcome.status
|
| 86 |
+
blocks._remember(Request(), outcome)
|
| 87 |
+
form.run(form.fn("_finish"), request=Request())
|
| 88 |
+
return outcome
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def sample_path(show_dir, mode_id: str) -> str:
|
| 92 |
+
return str((show_dir / SAMPLES[mode_id]).resolve())
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def jump_reads(form: Form) -> tuple[str | None, bool, bool]:
|
| 96 |
+
"""The control under the purpose line: (its words, shown, carries mr-over-run)."""
|
| 97 |
+
jump = form.by_id("sample-jump")
|
| 98 |
+
classes = form.props[jump._id].get("elem_classes") or ()
|
| 99 |
+
return (form.get(jump) if form.visible(jump) else None, form.visible(jump), OVER_RUN in classes)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def on_monitor(form: Form) -> str | None:
|
| 103 |
+
video, audio = form.by_id("video-out"), form.by_id("audio-out")
|
| 104 |
+
if form.visible(video) and form.get(video):
|
| 105 |
+
return str(form.get(video))
|
| 106 |
+
if form.visible(audio) and form.get(audio):
|
| 107 |
+
return str(form.get(audio))
|
| 108 |
+
return None
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def caption(form: Form) -> str:
|
| 112 |
+
return form.get(form.by_id("monitor-caption"))
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def test_run_then_switch_then_the_example_then_back_to_the_run(form, wired, show_dir):
|
| 116 |
+
run = a_run(form)
|
| 117 |
+
label = modes.get_mode("text_to_audio_video").label
|
| 118 |
+
assert on_monitor(form) == str(run.video)
|
| 119 |
+
assert caption(form) == f"**Your run.** {label}, seed {run.result.seed}."
|
| 120 |
+
assert jump_reads(form) == (None, False, False), "the run is the selected mode's own"
|
| 121 |
+
|
| 122 |
+
form.pick_mode("audio_to_audio")
|
| 123 |
+
assert on_monitor(form) == str(run.video), "the run stays when the mode changes (AC-06)"
|
| 124 |
+
assert caption(form).startswith("**Your run.**")
|
| 125 |
+
assert jump_reads(form) == ("See an example of Audio to audio", True, True)
|
| 126 |
+
|
| 127 |
+
form.click(form.by_id("sample-jump"))
|
| 128 |
+
assert on_monitor(form) == sample_path(show_dir, "audio_to_audio")
|
| 129 |
+
assert not form.visible(form.by_id("video-out")), "a sound sample plays in the sound player"
|
| 130 |
+
assert caption(form).startswith("**Example output, not your run.** Audio to audio")
|
| 131 |
+
assert jump_reads(form) == (render.BACK_TO_RUN, True, True)
|
| 132 |
+
assert render.BACK_TO_RUN == "Back to your run"
|
| 133 |
+
|
| 134 |
+
form.pick_mode("audio_to_video")
|
| 135 |
+
assert on_monitor(form) == sample_path(show_dir, "audio_to_video"), "later switches follow"
|
| 136 |
+
assert caption(form).startswith("**Example output, not your run.** Audio to video")
|
| 137 |
+
assert jump_reads(form) == (render.BACK_TO_RUN, True, True), "the run is still one click away"
|
| 138 |
+
|
| 139 |
+
form.click(form.by_id("sample-jump"))
|
| 140 |
+
assert on_monitor(form) == str(run.video)
|
| 141 |
+
assert caption(form) == f"**Your run.** {label}, seed {run.result.seed}."
|
| 142 |
+
assert jump_reads(form) == ("See an example of Audio to video", True, True)
|
| 143 |
+
|
| 144 |
+
form.pick_mode("text_to_audio_video")
|
| 145 |
+
assert on_monitor(form) == str(run.video)
|
| 146 |
+
assert jump_reads(form) == (None, False, False)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def test_a_mode_without_a_sample_offers_nothing_over_the_run(form, wired):
|
| 150 |
+
run = a_run(form)
|
| 151 |
+
form.pick_mode("text_to_video")
|
| 152 |
+
assert on_monitor(form) == str(run.video)
|
| 153 |
+
assert jump_reads(form) == (None, False, False)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def test_an_earlier_run_shown_from_recent_runs_works_the_same_way(form, wired, show_dir):
|
| 157 |
+
first = a_run(form)
|
| 158 |
+
second = a_run(form)
|
| 159 |
+
show = [b for b in form.fn("_finish").outputs if isinstance(b, gr.Button) and b.value == "Show"]
|
| 160 |
+
form.click(show[1])
|
| 161 |
+
label = modes.get_mode("text_to_audio_video").label
|
| 162 |
+
assert on_monitor(form) == str(first.video) != str(second.video)
|
| 163 |
+
assert caption(form) == f"**Earlier run.** {label}, seed {first.result.seed}."
|
| 164 |
+
|
| 165 |
+
form.pick_mode("audio_to_video")
|
| 166 |
+
assert jump_reads(form) == ("See an example of Audio to video", True, True)
|
| 167 |
+
form.click(form.by_id("sample-jump"))
|
| 168 |
+
assert on_monitor(form) == sample_path(show_dir, "audio_to_video")
|
| 169 |
+
form.click(form.by_id("sample-jump"))
|
| 170 |
+
assert on_monitor(form) == str(first.video)
|
| 171 |
+
assert caption(form) == f"**Earlier run.** {label}, seed {first.result.seed}."
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def test_a_run_finished_while_another_mode_is_selected_keeps_its_own_mode(form, wired):
|
| 175 |
+
"""The run's caption, its Recent row and the monitor state name the mode that ran, not the
|
| 176 |
+
one selected when it ended."""
|
| 177 |
+
values = {spec.key: spec.default for spec in FIELDS} | inputs_for("text_to_audio_video")
|
| 178 |
+
outcome = handlers.run("text_to_audio_video", *(values[k] for k in FIELD_KEYS))
|
| 179 |
+
form.pick_mode("audio_to_audio")
|
| 180 |
+
blocks._remember(Request(), outcome)
|
| 181 |
+
form.run(form.fn("_finish"), request=Request())
|
| 182 |
+
label = modes.get_mode("text_to_audio_video").label
|
| 183 |
+
assert caption(form).startswith(f"**Your run.** {label}, ")
|
| 184 |
+
recent = next(c for c in form.fn("_finish").outputs if isinstance(c, gr.State)
|
| 185 |
+
and isinstance(form.get(c), list) and form.get(c))
|
| 186 |
+
assert form.get(recent)[0]["mode"] == "text_to_audio_video"
|
| 187 |
+
assert jump_reads(form) == ("See an example of Audio to audio", True, True)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def test_back_to_a_run_whose_file_is_gone_is_not_offered(form, wired, show_dir):
|
| 191 |
+
from pathlib import Path
|
| 192 |
+
|
| 193 |
+
run = a_run(form)
|
| 194 |
+
form.pick_mode("audio_to_audio")
|
| 195 |
+
form.click(form.by_id("sample-jump"))
|
| 196 |
+
assert jump_reads(form)[0] == render.BACK_TO_RUN
|
| 197 |
+
Path(run.video).unlink()
|
| 198 |
+
form.pick_mode("audio_to_video")
|
| 199 |
+
assert jump_reads(form) == (render.SAMPLE_JUMP, True, False), (
|
| 200 |
+
"the run's file was evicted: only the plain jump to the sample is left"
|
| 201 |
+
)
|
| 202 |
+
assert on_monitor(form) == sample_path(show_dir, "audio_to_video")
|
| 203 |
+
form.click(form.by_id("sample-jump"))
|
| 204 |
+
assert on_monitor(form) == sample_path(show_dir, "audio_to_video"), "nothing to go back to"
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def test_with_no_run_the_jump_is_the_phones_plain_jump_to_the_sample(form):
|
| 208 |
+
assert jump_reads(form) == (render.SAMPLE_JUMP, True, False)
|
| 209 |
+
form.pick_mode("text_to_video")
|
| 210 |
+
assert jump_reads(form) == (None, False, False)
|
| 211 |
+
form.pick_mode("audio_to_audio")
|
| 212 |
+
assert jump_reads(form) == (render.SAMPLE_JUMP, True, False)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def test_a_new_run_drops_the_covered_run_and_hides_the_control(form, wired):
|
| 216 |
+
a_run(form)
|
| 217 |
+
form.pick_mode("audio_to_audio")
|
| 218 |
+
form.click(form.by_id("sample-jump"))
|
| 219 |
+
start = form.fn("_start")
|
| 220 |
+
out = start.fn("audio_to_audio", False, "", Request())
|
| 221 |
+
got = dict(zip(start.outputs, out, strict=True))
|
| 222 |
+
assert got[form.by_id("sample-jump")]["visible"] is False
|
| 223 |
+
state = next(v for c, v in got.items() if isinstance(c, gr.State) and isinstance(v, dict))
|
| 224 |
+
assert state == {"kind": "running", "mode": "audio_to_audio"}
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def test_the_click_passes_gradios_own_processing(show_dir, tmp_path):
|
| 228 |
+
"""The step as Gradio's queue runs it: the sample reaches the player as a file it serves,
|
| 229 |
+
and the control's words and class reach the page."""
|
| 230 |
+
import asyncio
|
| 231 |
+
|
| 232 |
+
from gradio.state_holder import SessionState
|
| 233 |
+
|
| 234 |
+
demo = blocks.build_ui()
|
| 235 |
+
step = next(f for f in demo.fns.values() if getattr(f.fn, "__name__", "") == "_on_jump")
|
| 236 |
+
monitor = next(c for c in step.inputs if isinstance(c, gr.State))
|
| 237 |
+
run_file = tmp_path / "output.mp4"
|
| 238 |
+
run_file.write_bytes(b"run")
|
| 239 |
+
state = SessionState(demo)
|
| 240 |
+
state[monitor._id] = blocks._run_state("text_to_audio_video", 5, run_file, run_file)
|
| 241 |
+
out = asyncio.run(
|
| 242 |
+
demo.process_api(
|
| 243 |
+
block_fn=step,
|
| 244 |
+
inputs=["audio_to_video", None],
|
| 245 |
+
state=state,
|
| 246 |
+
request=gr.Request(session_hash="jump"),
|
| 247 |
+
session_hash="jump",
|
| 248 |
+
in_event_listener=True,
|
| 249 |
+
)
|
| 250 |
+
)["data"]
|
| 251 |
+
got = {getattr(c, "elem_id", None): v for c, v in zip(step.outputs, out, strict=True)}
|
| 252 |
+
assert got["video-out"]["value"]["path"] == sample_path(show_dir, "audio_to_video")
|
| 253 |
+
assert got["monitor-caption"].startswith("**Example output, not your run.**")
|
| 254 |
+
assert got["sample-jump"]["value"] == render.BACK_TO_RUN
|
| 255 |
+
assert OVER_RUN in got["sample-jump"]["elem_classes"]
|
| 256 |
+
assert state[monitor._id]["covered"]["video"] == run_file
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def test_the_click_brings_the_monitor_into_view_below_1024px(form):
|
| 260 |
+
jump = form.by_id("sample-jump")
|
| 261 |
+
(listener,) = form.listeners(jump, "click")
|
| 262 |
+
js = listener.js
|
| 263 |
+
assert "scrollIntoView" in js and "getElementById('monitor')" in js
|
| 264 |
+
assert "innerWidth >= 1024" in js and "block: 'center'" in js
|
| 265 |
+
assert "return args" in js, "the step's inputs pass through to the handler"
|
| 266 |
+
assert listener.api_visibility == "private"
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def test_the_words_live_beside_the_sample_jump():
|
| 270 |
+
assert render.SAMPLE_JUMP == "See an example output"
|
| 271 |
+
assert render.sample_of(modes.get_mode("audio_to_audio")) == "See an example of Audio to audio"
|