Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,8 @@ def _coerce_audio_path(audio_path: Any) -> str:
|
|
| 34 |
|
| 35 |
# pathlib.Path etc.
|
| 36 |
if not isinstance(audio_path, (str, bytes, os.PathLike)):
|
|
|
|
|
|
|
| 37 |
raise TypeError(f"audio_path must be a path-like, got {type(audio_path)}: {audio_path}")
|
| 38 |
|
| 39 |
return os.fspath(audio_path)
|
|
@@ -89,6 +91,9 @@ def match_audio_to_duration(
|
|
| 89 |
Load audio, resample, (optionally) mono, then trim/pad to exactly target_seconds.
|
| 90 |
Returns: (waveform[T] or [1,T], sr)
|
| 91 |
"""
|
|
|
|
|
|
|
|
|
|
| 92 |
audio_path = _coerce_audio_path(audio_path)
|
| 93 |
|
| 94 |
wav, sr = torchaudio.load(audio_path) # [C, T] float32 CPU
|
|
@@ -547,690 +552,6 @@ print("Pipeline fully loaded and ready!")
|
|
| 547 |
print("=" * 80)
|
| 548 |
|
| 549 |
|
| 550 |
-
####################################################################################################
|
| 551 |
-
### PART 12: Custom Component - RadioAnimated
|
| 552 |
-
####################################################################################################
|
| 553 |
-
class RadioAnimated(gr.HTML):
|
| 554 |
-
"""
|
| 555 |
-
Animated segmented radio (like iOS pill selector).
|
| 556 |
-
Outputs: selected option string, e.g. "768x512"
|
| 557 |
-
"""
|
| 558 |
-
def __init__(self, choices, value=None, **kwargs):
|
| 559 |
-
if not choices or len(choices) < 2:
|
| 560 |
-
raise ValueError("RadioAnimated requires at least 2 choices.")
|
| 561 |
-
if value is None:
|
| 562 |
-
value = choices[0]
|
| 563 |
-
|
| 564 |
-
uid = uuid.uuid4().hex[:8] # unique per instance
|
| 565 |
-
group_name = f"ra-{uid}"
|
| 566 |
-
|
| 567 |
-
inputs_html = "\n".join(
|
| 568 |
-
f"""
|
| 569 |
-
<input class="ra-input" type="radio" name="{group_name}" id="{group_name}-{i}" value="{c}">
|
| 570 |
-
<label class="ra-label" for="{group_name}-{i}">{c}</label>
|
| 571 |
-
"""
|
| 572 |
-
for i, c in enumerate(choices)
|
| 573 |
-
)
|
| 574 |
-
|
| 575 |
-
# NOTE: use classes instead of duplicate IDs
|
| 576 |
-
html_template = f"""
|
| 577 |
-
<div class="ra-wrap" data-ra="{uid}">
|
| 578 |
-
<div class="ra-inner">
|
| 579 |
-
<div class="ra-highlight"></div>
|
| 580 |
-
{inputs_html}
|
| 581 |
-
</div>
|
| 582 |
-
</div>
|
| 583 |
-
"""
|
| 584 |
-
|
| 585 |
-
js_on_load = r"""
|
| 586 |
-
(() => {
|
| 587 |
-
const wrap = element.querySelector('.ra-wrap');
|
| 588 |
-
const inner = element.querySelector('.ra-inner');
|
| 589 |
-
const highlight = element.querySelector('.ra-highlight');
|
| 590 |
-
const inputs = Array.from(element.querySelectorAll('.ra-input'));
|
| 591 |
-
const labels = Array.from(element.querySelectorAll('.ra-label'));
|
| 592 |
-
|
| 593 |
-
if (!inputs.length || !labels.length) return;
|
| 594 |
-
|
| 595 |
-
const choices = inputs.map(i => i.value);
|
| 596 |
-
const PAD = 6; // must match .ra-inner padding and .ra-highlight top/left
|
| 597 |
-
|
| 598 |
-
let currentIdx = 0;
|
| 599 |
-
|
| 600 |
-
function setHighlightByIndex(idx) {
|
| 601 |
-
currentIdx = idx;
|
| 602 |
-
|
| 603 |
-
const lbl = labels[idx];
|
| 604 |
-
if (!lbl) return;
|
| 605 |
-
|
| 606 |
-
const innerRect = inner.getBoundingClientRect();
|
| 607 |
-
const lblRect = lbl.getBoundingClientRect();
|
| 608 |
-
|
| 609 |
-
// width matches the label exactly
|
| 610 |
-
highlight.style.width = `${lblRect.width}px`;
|
| 611 |
-
|
| 612 |
-
// highlight has left: 6px, so subtract PAD to align
|
| 613 |
-
const x = (lblRect.left - innerRect.left - PAD);
|
| 614 |
-
highlight.style.transform = `translateX(${x}px)`;
|
| 615 |
-
}
|
| 616 |
-
|
| 617 |
-
function setCheckedByValue(val, shouldTrigger=false) {
|
| 618 |
-
const idx = Math.max(0, choices.indexOf(val));
|
| 619 |
-
inputs.forEach((inp, i) => { inp.checked = (i === idx); });
|
| 620 |
-
|
| 621 |
-
// Wait a frame in case fonts/layout settle (prevents rare drift)
|
| 622 |
-
requestAnimationFrame(() => setHighlightByIndex(idx));
|
| 623 |
-
|
| 624 |
-
props.value = choices[idx];
|
| 625 |
-
if (shouldTrigger) trigger('change', props.value);
|
| 626 |
-
}
|
| 627 |
-
|
| 628 |
-
// Init
|
| 629 |
-
setCheckedByValue(props.value ?? choices[0], false);
|
| 630 |
-
|
| 631 |
-
// Input handlers
|
| 632 |
-
inputs.forEach((inp) => {
|
| 633 |
-
inp.addEventListener('change', () => setCheckedByValue(inp.value, true));
|
| 634 |
-
});
|
| 635 |
-
|
| 636 |
-
// Recalc on resize (important in Gradio layouts)
|
| 637 |
-
window.addEventListener('resize', () => setHighlightByIndex(currentIdx));
|
| 638 |
-
|
| 639 |
-
// sync from Python (Examples / backend updates)
|
| 640 |
-
let last = props.value;
|
| 641 |
-
const syncFromProps = () => {
|
| 642 |
-
if (props.value !== last) {
|
| 643 |
-
last = props.value;
|
| 644 |
-
setCheckedByValue(last, false);
|
| 645 |
-
}
|
| 646 |
-
requestAnimationFrame(syncFromProps);
|
| 647 |
-
};
|
| 648 |
-
requestAnimationFrame(syncFromProps);
|
| 649 |
-
|
| 650 |
-
})();
|
| 651 |
-
|
| 652 |
-
"""
|
| 653 |
-
|
| 654 |
-
super().__init__(
|
| 655 |
-
value=value,
|
| 656 |
-
html_template=html_template,
|
| 657 |
-
js_on_load=js_on_load,
|
| 658 |
-
**kwargs
|
| 659 |
-
)
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
####################################################################################################
|
| 663 |
-
### PART 13: Custom Component - PromptBox
|
| 664 |
-
####################################################################################################
|
| 665 |
-
class PromptBox(gr.HTML):
|
| 666 |
-
"""
|
| 667 |
-
Prompt textarea with an internal footer slot (.ds-footer) where we can inject dropdowns.
|
| 668 |
-
"""
|
| 669 |
-
def __init__(self, value="", placeholder="Describe what you want...", **kwargs):
|
| 670 |
-
uid = uuid.uuid4().hex[:8]
|
| 671 |
-
|
| 672 |
-
html_template = f"""
|
| 673 |
-
<div class="ds-card" data-ds="{uid}">
|
| 674 |
-
<div class="ds-top">
|
| 675 |
-
<textarea class="ds-textarea" rows="3" placeholder="{placeholder}"></textarea>
|
| 676 |
-
|
| 677 |
-
<!-- footer slot -->
|
| 678 |
-
<div class="ds-footer" aria-label="prompt-footer"></div>
|
| 679 |
-
</div>
|
| 680 |
-
</div>
|
| 681 |
-
"""
|
| 682 |
-
|
| 683 |
-
js_on_load = r"""
|
| 684 |
-
(() => {
|
| 685 |
-
const textarea = element.querySelector(".ds-textarea");
|
| 686 |
-
if (!textarea) return;
|
| 687 |
-
|
| 688 |
-
const autosize = () => {
|
| 689 |
-
textarea.style.height = "0px";
|
| 690 |
-
textarea.style.height = Math.min(textarea.scrollHeight, 240) + "px";
|
| 691 |
-
};
|
| 692 |
-
|
| 693 |
-
const setValue = (v, triggerChange=false) => {
|
| 694 |
-
const val = (v ?? "");
|
| 695 |
-
if (textarea.value !== val) textarea.value = val;
|
| 696 |
-
autosize();
|
| 697 |
-
props.value = textarea.value;
|
| 698 |
-
if (triggerChange) trigger("change", props.value);
|
| 699 |
-
};
|
| 700 |
-
|
| 701 |
-
setValue(props.value, false);
|
| 702 |
-
|
| 703 |
-
textarea.addEventListener("input", () => {
|
| 704 |
-
autosize();
|
| 705 |
-
props.value = textarea.value;
|
| 706 |
-
trigger("change", props.value);
|
| 707 |
-
});
|
| 708 |
-
|
| 709 |
-
// ✅ Focus-on-load (robust)
|
| 710 |
-
const shouldAutoFocus = () => {
|
| 711 |
-
// don’t steal focus if user already clicked/typed somewhere
|
| 712 |
-
const ae = document.activeElement;
|
| 713 |
-
if (ae && ae !== document.body && ae !== document.documentElement) return false;
|
| 714 |
-
// don’t auto-focus on small screens (optional; avoids mobile keyboard pop)
|
| 715 |
-
if (window.matchMedia && window.matchMedia("(max-width: 768px)").matches) return false;
|
| 716 |
-
return true;
|
| 717 |
-
};
|
| 718 |
-
|
| 719 |
-
const focusWithRetry = (tries = 30) => {
|
| 720 |
-
if (!shouldAutoFocus()) return;
|
| 721 |
-
// only focus if still not focused
|
| 722 |
-
if (document.activeElement !== textarea) textarea.focus({ preventScroll: true });
|
| 723 |
-
if (document.activeElement === textarea) return;
|
| 724 |
-
if (tries > 0) requestAnimationFrame(() => focusWithRetry(tries - 1));
|
| 725 |
-
};
|
| 726 |
-
|
| 727 |
-
// wait a tick so Gradio/layout settles
|
| 728 |
-
requestAnimationFrame(() => focusWithRetry());
|
| 729 |
-
|
| 730 |
-
// keep your sync loop
|
| 731 |
-
let last = props.value;
|
| 732 |
-
const syncFromProps = () => {
|
| 733 |
-
if (props.value !== last) {
|
| 734 |
-
last = props.value;
|
| 735 |
-
setValue(last, false);
|
| 736 |
-
}
|
| 737 |
-
requestAnimationFrame(syncFromProps);
|
| 738 |
-
};
|
| 739 |
-
requestAnimationFrame(syncFromProps);
|
| 740 |
-
})();
|
| 741 |
-
|
| 742 |
-
"""
|
| 743 |
-
|
| 744 |
-
super().__init__(value=value, html_template=html_template, js_on_load=js_on_load, **kwargs)
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
####################################################################################################
|
| 748 |
-
### PART 14: Custom Component - CameraDropdown
|
| 749 |
-
####################################################################################################
|
| 750 |
-
class CameraDropdown(gr.HTML):
|
| 751 |
-
"""
|
| 752 |
-
Custom dropdown (More-style) with optional icons per item.
|
| 753 |
-
Outputs: selected option string, e.g. "16:9"
|
| 754 |
-
"""
|
| 755 |
-
def __init__(self, choices, value="None", title="Dropdown", **kwargs):
|
| 756 |
-
if not choices:
|
| 757 |
-
raise ValueError("CameraDropdown requires choices.")
|
| 758 |
-
|
| 759 |
-
# Normalize choices -> list of dicts: {label, value, icon(optional)}
|
| 760 |
-
norm = []
|
| 761 |
-
for c in choices:
|
| 762 |
-
if isinstance(c, dict):
|
| 763 |
-
label = str(c.get("label", c.get("value", "")))
|
| 764 |
-
val = str(c.get("value", label))
|
| 765 |
-
icon = c.get("icon", None) # emoji or svg/html
|
| 766 |
-
norm.append({"label": label, "value": val, "icon": icon})
|
| 767 |
-
else:
|
| 768 |
-
s = str(c)
|
| 769 |
-
norm.append({"label": s, "value": s, "icon": None})
|
| 770 |
-
|
| 771 |
-
uid = uuid.uuid4().hex[:8]
|
| 772 |
-
|
| 773 |
-
def render_item(item):
|
| 774 |
-
icon_html = ""
|
| 775 |
-
if item["icon"]:
|
| 776 |
-
icon_html = f'<span class="cd-icn">{item["icon"]}</span>'
|
| 777 |
-
return (
|
| 778 |
-
f'<button type="button" class="cd-item" '
|
| 779 |
-
f'data-value="{item["value"]}">'
|
| 780 |
-
f'{icon_html}<span class="cd-label">{item["label"]}</span>'
|
| 781 |
-
f'</button>'
|
| 782 |
-
)
|
| 783 |
-
|
| 784 |
-
items_html = "\n".join(render_item(item) for item in norm)
|
| 785 |
-
|
| 786 |
-
html_template = f"""
|
| 787 |
-
<div class="cd-wrap" data-cd="{uid}">
|
| 788 |
-
<button type="button" class="cd-trigger" aria-haspopup="menu" aria-expanded="false">
|
| 789 |
-
<span class="cd-trigger-icon"></span>
|
| 790 |
-
<span class="cd-trigger-text"></span>
|
| 791 |
-
<span class="cd-caret">▾</span>
|
| 792 |
-
</button>
|
| 793 |
-
|
| 794 |
-
<div class="cd-menu" role="menu" aria-hidden="true">
|
| 795 |
-
<div class="cd-title">{title}</div>
|
| 796 |
-
<div class="cd-items">
|
| 797 |
-
{items_html}
|
| 798 |
-
</div>
|
| 799 |
-
</div>
|
| 800 |
-
</div>
|
| 801 |
-
"""
|
| 802 |
-
|
| 803 |
-
# Pass a mapping value->label so the trigger can show label text
|
| 804 |
-
# (and still output value to Python)
|
| 805 |
-
value_to_label = {it["value"]: it["label"] for it in norm}
|
| 806 |
-
value_to_icon = {it["value"]: (it["icon"] or "") for it in norm}
|
| 807 |
-
|
| 808 |
-
js_on_load = r"""
|
| 809 |
-
(() => {
|
| 810 |
-
const wrap = element.querySelector(".cd-wrap");
|
| 811 |
-
const trigger = element.querySelector(".cd-trigger");
|
| 812 |
-
const triggerIcon = element.querySelector(".cd-trigger-icon");
|
| 813 |
-
const triggerText = element.querySelector(".cd-trigger-text");
|
| 814 |
-
const menu = element.querySelector(".cd-menu");
|
| 815 |
-
const items = Array.from(element.querySelectorAll(".cd-item"));
|
| 816 |
-
if (!wrap || !trigger || !menu || !items.length) return;
|
| 817 |
-
|
| 818 |
-
const valueToLabel = __VALUE_TO_LABEL__;
|
| 819 |
-
const valueToIcon = __VALUE_TO_ICON__;
|
| 820 |
-
|
| 821 |
-
const safeLabel = (v) => (valueToLabel && valueToLabel[v]) ? valueToLabel[v] : (v ?? "None");
|
| 822 |
-
const safeIcon = (v) => (valueToIcon && valueToIcon[v]) ? valueToIcon[v] : "";
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
function closeMenu() {
|
| 826 |
-
menu.classList.remove("open");
|
| 827 |
-
trigger.setAttribute("aria-expanded", "false");
|
| 828 |
-
menu.setAttribute("aria-hidden", "true");
|
| 829 |
-
}
|
| 830 |
-
|
| 831 |
-
function openMenu() {
|
| 832 |
-
menu.classList.add("open");
|
| 833 |
-
trigger.setAttribute("aria-expanded", "true");
|
| 834 |
-
menu.setAttribute("aria-hidden", "false");
|
| 835 |
-
}
|
| 836 |
-
|
| 837 |
-
function setValue(val, shouldTrigger = false) {
|
| 838 |
-
const v = (val ?? "None");
|
| 839 |
-
props.value = v;
|
| 840 |
-
|
| 841 |
-
// Trigger shows LABEL only (icons stay in menu)
|
| 842 |
-
triggerText.textContent = safeLabel(v);
|
| 843 |
-
if (triggerIcon) {
|
| 844 |
-
triggerIcon.innerHTML = safeIcon(v);
|
| 845 |
-
triggerIcon.style.display = safeIcon(v) ? "inline-flex" : "none";
|
| 846 |
-
}
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
items.forEach(btn => {
|
| 850 |
-
btn.dataset.selected = (btn.dataset.value === v) ? "true" : "false";
|
| 851 |
-
});
|
| 852 |
-
|
| 853 |
-
if (shouldTrigger) trigger("change", props.value);
|
| 854 |
-
}
|
| 855 |
-
|
| 856 |
-
trigger.addEventListener("pointerdown", (e) => {
|
| 857 |
-
e.preventDefault();
|
| 858 |
-
e.stopPropagation();
|
| 859 |
-
if (menu.classList.contains("open")) closeMenu();
|
| 860 |
-
else openMenu();
|
| 861 |
-
});
|
| 862 |
-
|
| 863 |
-
document.addEventListener("pointerdown", (e) => {
|
| 864 |
-
if (!wrap.contains(e.target)) closeMenu();
|
| 865 |
-
}, true);
|
| 866 |
-
|
| 867 |
-
document.addEventListener("keydown", (e) => {
|
| 868 |
-
if (e.key === "Escape") closeMenu();
|
| 869 |
-
});
|
| 870 |
-
|
| 871 |
-
wrap.addEventListener("focusout", (e) => {
|
| 872 |
-
if (!wrap.contains(e.relatedTarget)) closeMenu();
|
| 873 |
-
});
|
| 874 |
-
|
| 875 |
-
items.forEach((btn) => {
|
| 876 |
-
btn.addEventListener("pointerdown", (e) => {
|
| 877 |
-
e.preventDefault();
|
| 878 |
-
e.stopPropagation();
|
| 879 |
-
closeMenu();
|
| 880 |
-
setValue(btn.dataset.value, true);
|
| 881 |
-
});
|
| 882 |
-
});
|
| 883 |
-
|
| 884 |
-
// init
|
| 885 |
-
setValue((props.value ?? "None"), false);
|
| 886 |
-
|
| 887 |
-
// sync from Python
|
| 888 |
-
let last = props.value;
|
| 889 |
-
const syncFromProps = () => {
|
| 890 |
-
if (props.value !== last) {
|
| 891 |
-
last = props.value;
|
| 892 |
-
setValue(last, false);
|
| 893 |
-
}
|
| 894 |
-
requestAnimationFrame(syncFromProps);
|
| 895 |
-
};
|
| 896 |
-
requestAnimationFrame(syncFromProps);
|
| 897 |
-
})();
|
| 898 |
-
"""
|
| 899 |
-
|
| 900 |
-
# Inject mapping into JS safely
|
| 901 |
-
import json
|
| 902 |
-
js_on_load = js_on_load.replace("__VALUE_TO_LABEL__", json.dumps(value_to_label))
|
| 903 |
-
js_on_load = js_on_load.replace("__VALUE_TO_ICON__", json.dumps(value_to_icon))
|
| 904 |
-
|
| 905 |
-
super().__init__(
|
| 906 |
-
value=value,
|
| 907 |
-
html_template=html_template,
|
| 908 |
-
js_on_load=js_on_load,
|
| 909 |
-
**kwargs
|
| 910 |
-
)
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
####################################################################################################
|
| 914 |
-
### PART 15: Custom Component - PresetGallery
|
| 915 |
-
####################################################################################################
|
| 916 |
-
class PresetGallery(gr.HTML):
|
| 917 |
-
"""
|
| 918 |
-
Clickable image presets -> outputs selected index (int as string, then cast in python)
|
| 919 |
-
"""
|
| 920 |
-
def __init__(self, items, title="Click an Example", **kwargs):
|
| 921 |
-
"""
|
| 922 |
-
items: list[dict] with keys:
|
| 923 |
-
- thumb: str (path to image file, e.g. "supergirl.png")
|
| 924 |
-
- label: str (optional)
|
| 925 |
-
"""
|
| 926 |
-
uid = uuid.uuid4().hex[:8]
|
| 927 |
-
|
| 928 |
-
cards_html = []
|
| 929 |
-
for i, it in enumerate(items):
|
| 930 |
-
thumb = it["thumb"]
|
| 931 |
-
label = it.get("label", "")
|
| 932 |
-
cards_html.append(f"""
|
| 933 |
-
<button type="button" class="pg-card" data-idx="{i}" aria-label="{label}">
|
| 934 |
-
<img class="pg-img" src="gradio_api/file={thumb}" alt="{label}">
|
| 935 |
-
</button>
|
| 936 |
-
""")
|
| 937 |
-
|
| 938 |
-
html_template = f"""
|
| 939 |
-
<div class="pg-wrap" data-pg="{uid}">
|
| 940 |
-
<div class="pg-title">
|
| 941 |
-
<div class="pg-h1">{title}</div>
|
| 942 |
-
</div>
|
| 943 |
-
<div class="pg-grid">
|
| 944 |
-
{''.join(cards_html)}
|
| 945 |
-
</div>
|
| 946 |
-
</div>
|
| 947 |
-
"""
|
| 948 |
-
|
| 949 |
-
# --- JAVASCRIPT LOGIC UPDATED ---
|
| 950 |
-
# Removed "pointerenter" and "pointerleave" events.
|
| 951 |
-
# All logic is now inside "pointerdown" (click event).
|
| 952 |
-
js_on_load = r"""
|
| 953 |
-
(() => {
|
| 954 |
-
const wrap = element.querySelector(".pg-wrap");
|
| 955 |
-
const cards = Array.from(element.querySelectorAll(".pg-card"));
|
| 956 |
-
if (!wrap || !cards.length) return;
|
| 957 |
-
|
| 958 |
-
function setDim(activeIdx) {
|
| 959 |
-
cards.forEach((c, i) => {
|
| 960 |
-
// Dim cards that are not the active one.
|
| 961 |
-
c.dataset.dim = (activeIdx !== null && i !== activeIdx) ? "true" : "false";
|
| 962 |
-
// Set the active state for the clicked card.
|
| 963 |
-
c.dataset.active = (i === activeIdx) ? "true" : "false";
|
| 964 |
-
});
|
| 965 |
-
}
|
| 966 |
-
|
| 967 |
-
let lastSent = null;
|
| 968 |
-
let lock = false;
|
| 969 |
-
|
| 970 |
-
cards.forEach((card) => {
|
| 971 |
-
// REMOVED: "pointerenter" event listener. No action on hover.
|
| 972 |
-
// REMOVED: "pointerleave" event listener. No action on hover.
|
| 973 |
-
|
| 974 |
-
// Use pointerdown (click/tap) for all actions.
|
| 975 |
-
card.addEventListener("pointerdown", (e) => {
|
| 976 |
-
e.preventDefault();
|
| 977 |
-
e.stopPropagation();
|
| 978 |
-
|
| 979 |
-
if (lock) return;
|
| 980 |
-
lock = true;
|
| 981 |
-
setTimeout(() => (lock = false), 250);
|
| 982 |
-
|
| 983 |
-
const idxNumber = Number(card.dataset.idx);
|
| 984 |
-
const idxString = String(idxNumber);
|
| 985 |
-
|
| 986 |
-
// 1. Update visual state immediately on click.
|
| 987 |
-
setDim(idxNumber);
|
| 988 |
-
|
| 989 |
-
// 2. Only update Python backend if the value has actually changed.
|
| 990 |
-
if (idxString === lastSent) return;
|
| 991 |
-
lastSent = idxString;
|
| 992 |
-
|
| 993 |
-
// ✅ Set props.value to send data to Python.
|
| 994 |
-
props.value = idxString;
|
| 995 |
-
}, { passive: false });
|
| 996 |
-
});
|
| 997 |
-
|
| 998 |
-
// Initially, no card is selected.
|
| 999 |
-
setDim(null);
|
| 1000 |
-
})();
|
| 1001 |
-
"""
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
super().__init__(value="", html_template=html_template, js_on_load=js_on_load, **kwargs)
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
####################################################################################################
|
| 1008 |
-
### PART 16: Custom Component - AudioDropUpload
|
| 1009 |
-
####################################################################################################
|
| 1010 |
-
class AudioDropUpload(gr.HTML):
|
| 1011 |
-
"""
|
| 1012 |
-
Custom audio drop/click UI that proxies file into a hidden gr.Audio component.
|
| 1013 |
-
IMPORTANT:
|
| 1014 |
-
- Pass target_audio_elem_id = elem_id of your hidden gr.Audio.
|
| 1015 |
-
- The hidden gr.Audio must be type="filepath" (or whatever you need).
|
| 1016 |
-
"""
|
| 1017 |
-
def __init__(self, target_audio_elem_id: str, value=None, **kwargs):
|
| 1018 |
-
uid = uuid.uuid4().hex[:8]
|
| 1019 |
-
|
| 1020 |
-
html_template = f"""
|
| 1021 |
-
<div class="aud-wrap" data-aud="{uid}">
|
| 1022 |
-
<div class="aud-drop" role="button" tabindex="0" aria-label="بارگذاری صدا">
|
| 1023 |
-
<div><strong>(اختیاری) فایل صوتی را اینجا بکشید و رها کنید</strong></div>
|
| 1024 |
-
<div class="aud-hint">…یا برای انتخاب کلیک کنید</div>
|
| 1025 |
-
</div>
|
| 1026 |
-
<div class="aud-row" aria-live="polite">
|
| 1027 |
-
<audio class="aud-player" controls></audio>
|
| 1028 |
-
<button class="aud-remove" type="button" aria-label="حذف صدا">
|
| 1029 |
-
<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
|
| 1030 |
-
<path d="M18 6L6 18M6 6l12 12"
|
| 1031 |
-
stroke="currentColor"
|
| 1032 |
-
stroke-width="2.25"
|
| 1033 |
-
stroke-linecap="round"/>
|
| 1034 |
-
</svg>
|
| 1035 |
-
</button>
|
| 1036 |
-
</div>
|
| 1037 |
-
<div class="aud-filelabel"></div>
|
| 1038 |
-
</div>
|
| 1039 |
-
"""
|
| 1040 |
-
|
| 1041 |
-
# JS:
|
| 1042 |
-
# - finds the hidden gr.Audio upload <input type=file> inside the component with elem_id=target_audio_elem_id
|
| 1043 |
-
# - sets the selected file onto it (DataTransfer) and dispatches change
|
| 1044 |
-
js_on_load = """
|
| 1045 |
-
(() => {{
|
| 1046 |
-
// Helper: access Gradio shadow DOM safely
|
| 1047 |
-
function grRoot() {{
|
| 1048 |
-
const ga = document.querySelector("gradio-app");
|
| 1049 |
-
return (ga && ga.shadowRoot) ? ga.shadowRoot : document;
|
| 1050 |
-
}}
|
| 1051 |
-
const root = grRoot();
|
| 1052 |
-
const wrap = element.querySelector(".aud-wrap");
|
| 1053 |
-
const drop = element.querySelector(".aud-drop");
|
| 1054 |
-
const row = element.querySelector(".aud-row");
|
| 1055 |
-
const player = element.querySelector(".aud-player");
|
| 1056 |
-
const removeBtn = element.querySelector(".aud-remove");
|
| 1057 |
-
const label = element.querySelector(".aud-filelabel");
|
| 1058 |
-
const TARGET_ID = "__TARGET_ID__";
|
| 1059 |
-
let currentUrl = null;
|
| 1060 |
-
function findHiddenAudioFileInput() {{
|
| 1061 |
-
const host = root.querySelector("#" + CSS.escape(TARGET_ID));
|
| 1062 |
-
if (!host) return null;
|
| 1063 |
-
// Gradio's Audio component contains an <input type=file> for upload.
|
| 1064 |
-
// This selector works in most Gradio 3/4 themes.
|
| 1065 |
-
const inp = host.querySelector('input[type="file"]');
|
| 1066 |
-
return inp;
|
| 1067 |
-
}}
|
| 1068 |
-
function showDrop() {{
|
| 1069 |
-
drop.style.display = "";
|
| 1070 |
-
row.style.display = "none";
|
| 1071 |
-
label.style.display = "none";
|
| 1072 |
-
label.textContent = "";
|
| 1073 |
-
}}
|
| 1074 |
-
function showPlayer(filename) {{
|
| 1075 |
-
drop.style.display = "none";
|
| 1076 |
-
row.style.display = "flex";
|
| 1077 |
-
if (filename) {{
|
| 1078 |
-
label.textContent = "فایل بارگذاری شده: " + filename;
|
| 1079 |
-
label.style.display = "block";
|
| 1080 |
-
}}
|
| 1081 |
-
}}
|
| 1082 |
-
function clearPreview() {{
|
| 1083 |
-
player.pause();
|
| 1084 |
-
player.removeAttribute("src");
|
| 1085 |
-
player.load();
|
| 1086 |
-
if (currentUrl) {{
|
| 1087 |
-
URL.revokeObjectURL(currentUrl);
|
| 1088 |
-
currentUrl = null;
|
| 1089 |
-
}}
|
| 1090 |
-
}}
|
| 1091 |
-
function clearHiddenGradioAudio() {{
|
| 1092 |
-
const fileInput = findHiddenAudioFileInput();
|
| 1093 |
-
if (!fileInput) return;
|
| 1094 |
-
// Clear file input (works by replacing its files with empty DataTransfer)
|
| 1095 |
-
fileInput.value = "";
|
| 1096 |
-
const dt = new DataTransfer();
|
| 1097 |
-
fileInput.files = dt.files;
|
| 1098 |
-
fileInput.dispatchEvent(new Event("input", {{ bubbles: true }}));
|
| 1099 |
-
fileInput.dispatchEvent(new Event("change", {{ bubbles: true }}));
|
| 1100 |
-
}}
|
| 1101 |
-
function clearAll() {
|
| 1102 |
-
clearPreview();
|
| 1103 |
-
|
| 1104 |
-
// Attempt DOM clear (still useful)
|
| 1105 |
-
clearHiddenGradioAudio();
|
| 1106 |
-
|
| 1107 |
-
// Tell Gradio/Python explicitly to clear backend state
|
| 1108 |
-
props.value = "__CLEAR__";
|
| 1109 |
-
trigger("change", props.value);
|
| 1110 |
-
|
| 1111 |
-
showDrop();
|
| 1112 |
-
}
|
| 1113 |
-
|
| 1114 |
-
function loadFileToPreview(file) {{
|
| 1115 |
-
if (!file) return;
|
| 1116 |
-
if (!file.type || !file.type.startsWith("audio/")) {{
|
| 1117 |
-
alert("لطفا یک فایل صوتی انتخاب کنید.");
|
| 1118 |
-
return;
|
| 1119 |
-
}}
|
| 1120 |
-
clearPreview();
|
| 1121 |
-
currentUrl = URL.createObjectURL(file);
|
| 1122 |
-
player.src = currentUrl;
|
| 1123 |
-
showPlayer(file.name);
|
| 1124 |
-
|
| 1125 |
-
}}
|
| 1126 |
-
function pushFileIntoHiddenGradioAudio(file) {
|
| 1127 |
-
const fileInput = findHiddenAudioFileInput();
|
| 1128 |
-
if (!fileInput) {
|
| 1129 |
-
console.warn("Could not find hidden gr.File input. Check elem_id:", TARGET_ID);
|
| 1130 |
-
return;
|
| 1131 |
-
}
|
| 1132 |
-
|
| 1133 |
-
// Hard reset (important for re-selecting same file)
|
| 1134 |
-
fileInput.value = "";
|
| 1135 |
-
|
| 1136 |
-
const dt = new DataTransfer();
|
| 1137 |
-
dt.items.add(file);
|
| 1138 |
-
fileInput.files = dt.files;
|
| 1139 |
-
|
| 1140 |
-
// Trigger Gradio listeners
|
| 1141 |
-
fileInput.dispatchEvent(new Event("input", {{ bubbles: true }}));
|
| 1142 |
-
fileInput.dispatchEvent(new Event("change", {{ bubbles: true }}));
|
| 1143 |
-
}
|
| 1144 |
-
|
| 1145 |
-
function handleFile(file) {{
|
| 1146 |
-
loadFileToPreview(file);
|
| 1147 |
-
pushFileIntoHiddenGradioAudio(file);
|
| 1148 |
-
}}
|
| 1149 |
-
// Click-to-browse uses a *local* ephemeral input (not Gradio’s),
|
| 1150 |
-
// then we forward to hidden gr.Audio.
|
| 1151 |
-
const localPicker = document.createElement("input");
|
| 1152 |
-
localPicker.type = "file";
|
| 1153 |
-
localPicker.accept = "audio/*";
|
| 1154 |
-
localPicker.style.display = "none";
|
| 1155 |
-
wrap.appendChild(localPicker);
|
| 1156 |
-
localPicker.addEventListener("change", () => {{
|
| 1157 |
-
const f = localPicker.files && localPicker.files[0];
|
| 1158 |
-
if (f) handleFile(f);
|
| 1159 |
-
localPicker.value = "";
|
| 1160 |
-
}});
|
| 1161 |
-
drop.addEventListener("click", () => localPicker.click());
|
| 1162 |
-
drop.addEventListener("keydown", (e) => {{
|
| 1163 |
-
if (e.key === "Enter" || e.key === " ") {{
|
| 1164 |
-
e.preventDefault();
|
| 1165 |
-
localPicker.click();
|
| 1166 |
-
}}
|
| 1167 |
-
}});
|
| 1168 |
-
removeBtn.addEventListener("click", clearAll);
|
| 1169 |
-
// Drag & drop
|
| 1170 |
-
["dragenter","dragover","dragleave","drop"].forEach(evt => {{
|
| 1171 |
-
drop.addEventListener(evt, (e) => {{
|
| 1172 |
-
e.preventDefault();
|
| 1173 |
-
e.stopPropagation();
|
| 1174 |
-
}});
|
| 1175 |
-
}});
|
| 1176 |
-
drop.addEventListener("dragover", () => drop.classList.add("dragover"));
|
| 1177 |
-
drop.addEventListener("dragleave", () => drop.classList.remove("dragover"));
|
| 1178 |
-
drop.addEventListener("drop", (e) => {{
|
| 1179 |
-
drop.classList.remove("dragover");
|
| 1180 |
-
const f = e.dataTransfer.files && e.dataTransfer.files[0];
|
| 1181 |
-
if (f) handleFile(f);
|
| 1182 |
-
}});
|
| 1183 |
-
// init
|
| 1184 |
-
showDrop();
|
| 1185 |
-
|
| 1186 |
-
function setPreviewFromPath(path) {
|
| 1187 |
-
if (path === "__CLEAR__") path = null;
|
| 1188 |
-
|
| 1189 |
-
if (!path) {
|
| 1190 |
-
clearPreview();
|
| 1191 |
-
showDrop();
|
| 1192 |
-
return;
|
| 1193 |
-
}
|
| 1194 |
-
|
| 1195 |
-
// If path already looks like a URL, use it directly
|
| 1196 |
-
// otherwise serve it through Gradio's file route.
|
| 1197 |
-
let url = path;
|
| 1198 |
-
if (!/^https?:\/\//.test(path) && !path.startsWith("gradio_api/file=") && !path.startsWith("/file=")) {
|
| 1199 |
-
url = "gradio_api/file=" + path;
|
| 1200 |
-
}
|
| 1201 |
-
|
| 1202 |
-
clearPreview();
|
| 1203 |
-
player.src = url;
|
| 1204 |
-
showPlayer(path.split("/").pop());
|
| 1205 |
-
}
|
| 1206 |
-
|
| 1207 |
-
// ---- sync from Python (Examples / backend updates) ----
|
| 1208 |
-
let last = props.value;
|
| 1209 |
-
const syncFromProps = () => {
|
| 1210 |
-
const v = props.value;
|
| 1211 |
-
|
| 1212 |
-
if (v !== last) {
|
| 1213 |
-
last = v;
|
| 1214 |
-
if (!v || v === "__CLEAR__") setPreviewFromPath(null);
|
| 1215 |
-
else setPreviewFromPath(String(v));
|
| 1216 |
-
}
|
| 1217 |
-
requestAnimationFrame(syncFromProps);
|
| 1218 |
-
};
|
| 1219 |
-
requestAnimationFrame(syncFromProps);
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
}})();
|
| 1223 |
-
"""
|
| 1224 |
-
js_on_load = js_on_load.replace("__TARGET_ID__", target_audio_elem_id)
|
| 1225 |
-
|
| 1226 |
-
super().__init__(
|
| 1227 |
-
value=value,
|
| 1228 |
-
html_template=html_template,
|
| 1229 |
-
js_on_load=js_on_load,
|
| 1230 |
-
**kwargs
|
| 1231 |
-
)
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
####################################################################################################
|
| 1235 |
### PART 17: Wrapper Functions (Resolution, Duration, Examples)
|
| 1236 |
####################################################################################################
|
|
@@ -1458,7 +779,11 @@ def apply_resolution(resolution: str):
|
|
| 1458 |
return int(w), int(h)
|
| 1459 |
|
| 1460 |
def apply_duration(duration: str):
|
| 1461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1462 |
return duration_s
|
| 1463 |
|
| 1464 |
def on_mode_change(selected: str):
|
|
@@ -1473,51 +798,10 @@ def on_mode_change(selected: str):
|
|
| 1473 |
### PART 19: CSS Styles
|
| 1474 |
####################################################################################################
|
| 1475 |
css = """
|
| 1476 |
-
|
| 1477 |
-
/* Make the row behave nicely */
|
| 1478 |
-
#controls-row {
|
| 1479 |
-
display: none !important;
|
| 1480 |
-
align-items: center;
|
| 1481 |
-
gap: 12px;
|
| 1482 |
-
flex-wrap: nowrap; /* or wrap if you prefer on small screens */
|
| 1483 |
-
}
|
| 1484 |
-
|
| 1485 |
-
/* Stop these components from stretching */
|
| 1486 |
-
#controls-row > * {
|
| 1487 |
-
flex: 0 0 auto !important;
|
| 1488 |
-
width: auto !important;
|
| 1489 |
-
min-width: 0 !important;
|
| 1490 |
-
}
|
| 1491 |
-
|
| 1492 |
-
|
| 1493 |
#col-container {
|
| 1494 |
margin: 0 auto;
|
| 1495 |
max-width: 1600px;
|
| 1496 |
}
|
| 1497 |
-
#modal-container {
|
| 1498 |
-
width: 100vw; /* Take full viewport width */
|
| 1499 |
-
height: 100vh; /* Take full viewport height (optional) */
|
| 1500 |
-
display: flex;
|
| 1501 |
-
justify-content: center; /* Center content horizontally */
|
| 1502 |
-
align-items: center; /* Center content vertically if desired */
|
| 1503 |
-
}
|
| 1504 |
-
#modal-content {
|
| 1505 |
-
width: 100%;
|
| 1506 |
-
max-width: 700px; /* Limit content width */
|
| 1507 |
-
margin: 0 auto;
|
| 1508 |
-
border-radius: 8px;
|
| 1509 |
-
padding: 1.5rem;
|
| 1510 |
-
}
|
| 1511 |
-
#step-column {
|
| 1512 |
-
padding: 10px;
|
| 1513 |
-
border-radius: 8px;
|
| 1514 |
-
box-shadow: var(--card-shadow);
|
| 1515 |
-
margin: 10px;
|
| 1516 |
-
}
|
| 1517 |
-
#col-showcase {
|
| 1518 |
-
margin: 0 auto;
|
| 1519 |
-
max-width: 1100px;
|
| 1520 |
-
}
|
| 1521 |
.button-gradient {
|
| 1522 |
background: linear-gradient(45deg, rgb(255, 65, 108), rgb(255, 75, 43), rgb(255, 155, 0), rgb(255, 65, 108)) 0% 0% / 400% 400%;
|
| 1523 |
border: none;
|
|
@@ -1531,774 +815,28 @@ css = """
|
|
| 1531 |
animation: 2s linear 0s infinite normal none running gradientAnimation;
|
| 1532 |
box-shadow: rgba(255, 65, 108, 0.6) 0px 4px 10px;
|
| 1533 |
}
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
padding: 4px;
|
| 1539 |
-
position: relative;
|
| 1540 |
-
width: fit-content;
|
| 1541 |
-
font-family: sans-serif;
|
| 1542 |
-
}
|
| 1543 |
-
.toggle-container input[type="radio"] {
|
| 1544 |
-
display: none;
|
| 1545 |
-
}
|
| 1546 |
-
.toggle-container label {
|
| 1547 |
-
position: relative;
|
| 1548 |
-
z-index: 2;
|
| 1549 |
-
flex: 1;
|
| 1550 |
-
text-align: center;
|
| 1551 |
-
font-weight: 700;
|
| 1552 |
-
color: #4b2ab5; /* dark purple text for unselected */
|
| 1553 |
-
padding: 6px 22px;
|
| 1554 |
-
border-radius: 9999px;
|
| 1555 |
-
cursor: pointer;
|
| 1556 |
-
transition: color 0.25s ease;
|
| 1557 |
-
}
|
| 1558 |
-
/* Moving highlight */
|
| 1559 |
-
.toggle-highlight {
|
| 1560 |
-
position: absolute;
|
| 1561 |
-
top: 4px;
|
| 1562 |
-
left: 4px;
|
| 1563 |
-
width: calc(50% - 4px);
|
| 1564 |
-
height: calc(100% - 8px);
|
| 1565 |
-
background-color: #4b2ab5; /* dark purple background */
|
| 1566 |
-
border-radius: 9999px;
|
| 1567 |
-
transition: transform 0.25s ease;
|
| 1568 |
-
z-index: 1;
|
| 1569 |
-
}
|
| 1570 |
-
/* When "True" is checked */
|
| 1571 |
-
#true:checked ~ label[for="true"] {
|
| 1572 |
-
color: #ffd6ff; /* light pink text */
|
| 1573 |
-
}
|
| 1574 |
-
/* When "False" is checked */
|
| 1575 |
-
#false:checked ~ label[for="false"] {
|
| 1576 |
-
color: #ffd6ff; /* light pink text */
|
| 1577 |
-
}
|
| 1578 |
-
/* Move highlight to right side when False is checked */
|
| 1579 |
-
#false:checked ~ .toggle-highlight {
|
| 1580 |
-
transform: translateX(100%);
|
| 1581 |
-
}
|
| 1582 |
-
|
| 1583 |
-
/* Center items inside that row */
|
| 1584 |
-
#mode-row{
|
| 1585 |
-
justify-content: center !important;
|
| 1586 |
-
align-items: center !important;
|
| 1587 |
-
}
|
| 1588 |
-
|
| 1589 |
-
/* Center the mode row contents */
|
| 1590 |
-
#mode-row {
|
| 1591 |
-
display: flex !important;
|
| 1592 |
-
justify-content: center !important;
|
| 1593 |
-
align-items: center !important;
|
| 1594 |
-
width: 100% !important;
|
| 1595 |
-
}
|
| 1596 |
-
|
| 1597 |
-
/* Stop Gradio from making children stretch */
|
| 1598 |
-
#mode-row > * {
|
| 1599 |
-
flex: 0 0 auto !important;
|
| 1600 |
-
width: auto !important;
|
| 1601 |
-
min-width: 0 !important;
|
| 1602 |
-
}
|
| 1603 |
-
|
| 1604 |
-
/* Specifically ensure the HTML component wrapper doesn't take full width */
|
| 1605 |
-
#mode-row .gr-html,
|
| 1606 |
-
#mode-row .gradio-html,
|
| 1607 |
-
#mode-row .prose,
|
| 1608 |
-
#mode-row .block {
|
| 1609 |
-
width: auto !important;
|
| 1610 |
-
flex: 0 0 auto !important;
|
| 1611 |
-
display: inline-block !important;
|
| 1612 |
-
}
|
| 1613 |
-
|
| 1614 |
-
/* Center the pill itself */
|
| 1615 |
-
#radioanimated_mode {
|
| 1616 |
-
display: inline-flex !important;
|
| 1617 |
-
justify-content: center !important;
|
| 1618 |
-
width: auto !important;
|
| 1619 |
-
}
|
| 1620 |
-
|
| 1621 |
-
"""
|
| 1622 |
-
|
| 1623 |
-
css += """
|
| 1624 |
-
.cd-trigger-icon{
|
| 1625 |
-
color: rgba(255,255,255,0.9);
|
| 1626 |
-
display: inline-flex;
|
| 1627 |
-
align-items: center;
|
| 1628 |
-
justify-content: center;
|
| 1629 |
-
width: 18px;
|
| 1630 |
-
height: 18px;
|
| 1631 |
-
}
|
| 1632 |
-
.cd-trigger-icon svg {
|
| 1633 |
-
width: 18px;
|
| 1634 |
-
height: 18px;
|
| 1635 |
-
display: block;
|
| 1636 |
-
}
|
| 1637 |
-
"""
|
| 1638 |
-
|
| 1639 |
-
|
| 1640 |
-
css += """
|
| 1641 |
-
/* ---- radioanimated ---- */
|
| 1642 |
-
.ra-wrap{
|
| 1643 |
-
width: fit-content;
|
| 1644 |
-
}
|
| 1645 |
-
.ra-inner{
|
| 1646 |
-
position: relative;
|
| 1647 |
-
display: inline-flex;
|
| 1648 |
-
align-items: center;
|
| 1649 |
-
gap: 0;
|
| 1650 |
-
padding: 6px;
|
| 1651 |
-
background: #0b0b0b;
|
| 1652 |
-
border-radius: 9999px;
|
| 1653 |
-
overflow: hidden;
|
| 1654 |
-
user-select: none;
|
| 1655 |
-
}
|
| 1656 |
-
.ra-input{
|
| 1657 |
-
display: none;
|
| 1658 |
-
}
|
| 1659 |
-
.ra-label{
|
| 1660 |
-
position: relative;
|
| 1661 |
-
z-index: 2;
|
| 1662 |
-
padding: 10px 18px;
|
| 1663 |
-
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
|
| 1664 |
-
font-size: 14px;
|
| 1665 |
-
font-weight: 600;
|
| 1666 |
-
color: rgba(255,255,255,0.7);
|
| 1667 |
-
cursor: pointer;
|
| 1668 |
-
transition: color 180ms ease;
|
| 1669 |
-
white-space: nowrap;
|
| 1670 |
-
}
|
| 1671 |
-
.ra-highlight{
|
| 1672 |
-
position: absolute;
|
| 1673 |
-
z-index: 1;
|
| 1674 |
-
top: 6px;
|
| 1675 |
-
left: 6px;
|
| 1676 |
-
height: calc(100% - 12px);
|
| 1677 |
-
border-radius: 9999px;
|
| 1678 |
-
background: #8bff97; /* green knob */
|
| 1679 |
-
transition: transform 200ms ease, width 200ms ease;
|
| 1680 |
-
}
|
| 1681 |
-
/* selected label becomes darker like your screenshot */
|
| 1682 |
-
.ra-input:checked + .ra-label{
|
| 1683 |
-
color: rgba(0,0,0,0.75);
|
| 1684 |
-
}
|
| 1685 |
-
"""
|
| 1686 |
-
|
| 1687 |
-
css += """
|
| 1688 |
-
.cd-icn svg{
|
| 1689 |
-
width: 18px;
|
| 1690 |
-
height: 18px;
|
| 1691 |
-
display: block;
|
| 1692 |
-
}
|
| 1693 |
-
.cd-icn svg *{
|
| 1694 |
-
stroke: rgba(255,255,255,0.9);
|
| 1695 |
-
}
|
| 1696 |
-
"""
|
| 1697 |
-
|
| 1698 |
-
|
| 1699 |
-
css += """
|
| 1700 |
-
/* --- prompt box --- */
|
| 1701 |
-
.ds-prompt{
|
| 1702 |
-
width: 100%;
|
| 1703 |
-
max-width: 720px;
|
| 1704 |
-
margin-top: 3px;
|
| 1705 |
-
}
|
| 1706 |
-
|
| 1707 |
-
.ds-textarea{
|
| 1708 |
-
width: 100%;
|
| 1709 |
-
box-sizing: border-box;
|
| 1710 |
-
background: #2b2b2b;
|
| 1711 |
-
color: rgba(255,255,255,0.9);
|
| 1712 |
-
border: 1px solid rgba(255,255,255,0.12);
|
| 1713 |
-
border-radius: 14px;
|
| 1714 |
-
padding: 14px 16px;
|
| 1715 |
-
outline: none;
|
| 1716 |
-
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
|
| 1717 |
-
font-size: 15px;
|
| 1718 |
-
line-height: 1.35;
|
| 1719 |
-
resize: none;
|
| 1720 |
-
min-height: 210px;
|
| 1721 |
-
max-height: 210px;
|
| 1722 |
-
overflow-y: auto;
|
| 1723 |
-
|
| 1724 |
-
/* IMPORTANT: space for the footer controls */
|
| 1725 |
-
padding-bottom: 72px;
|
| 1726 |
-
}
|
| 1727 |
-
|
| 1728 |
-
|
| 1729 |
-
.ds-card{
|
| 1730 |
-
width: 100%;
|
| 1731 |
-
max-width: 720px;
|
| 1732 |
-
margin: 0 auto;
|
| 1733 |
-
}
|
| 1734 |
-
.ds-top{
|
| 1735 |
-
position: relative;
|
| 1736 |
-
}
|
| 1737 |
-
|
| 1738 |
-
/* Make room for footer inside textarea */
|
| 1739 |
-
.ds-textarea{
|
| 1740 |
-
padding-bottom: 72px;
|
| 1741 |
-
}
|
| 1742 |
-
|
| 1743 |
-
/* Footer positioning */
|
| 1744 |
-
.ds-footer{
|
| 1745 |
-
position: absolute;
|
| 1746 |
-
right: 12px;
|
| 1747 |
-
bottom: 10px;
|
| 1748 |
-
display: flex;
|
| 1749 |
-
gap: 8px;
|
| 1750 |
-
align-items: center;
|
| 1751 |
-
justify-content: flex-end;
|
| 1752 |
-
z-index: 3;
|
| 1753 |
-
}
|
| 1754 |
-
|
| 1755 |
-
/* Smaller pill buttons inside footer */
|
| 1756 |
-
.ds-footer .cd-trigger{
|
| 1757 |
-
min-height: 32px;
|
| 1758 |
-
padding: 6px 10px;
|
| 1759 |
-
font-size: 12px;
|
| 1760 |
-
gap: 6px;
|
| 1761 |
-
border-radius: 9999px;
|
| 1762 |
-
}
|
| 1763 |
-
.ds-footer .cd-trigger-icon,
|
| 1764 |
-
.ds-footer .cd-icn{
|
| 1765 |
-
width: 14px;
|
| 1766 |
-
height: 14px;
|
| 1767 |
-
}
|
| 1768 |
-
.ds-footer .cd-trigger-icon svg,
|
| 1769 |
-
.ds-footer .cd-icn svg{
|
| 1770 |
-
width: 14px;
|
| 1771 |
-
height: 14px;
|
| 1772 |
-
}
|
| 1773 |
-
.ds-footer .cd-caret{
|
| 1774 |
-
font-size: 11px;
|
| 1775 |
-
}
|
| 1776 |
-
|
| 1777 |
-
/* Bottom safe area bar (optional but looks nicer) */
|
| 1778 |
-
.ds-top::after{
|
| 1779 |
-
content: "";
|
| 1780 |
-
position: absolute;
|
| 1781 |
-
left: 1px;
|
| 1782 |
-
right: 1px;
|
| 1783 |
-
bottom: 1px;
|
| 1784 |
-
height: 56px;
|
| 1785 |
-
background: #2b2b2b;
|
| 1786 |
-
border-bottom-left-radius: 13px;
|
| 1787 |
-
border-bottom-right-radius: 13px;
|
| 1788 |
-
pointer-events: none;
|
| 1789 |
-
z-index: 2;
|
| 1790 |
-
}
|
| 1791 |
-
|
| 1792 |
-
"""
|
| 1793 |
-
|
| 1794 |
-
css += """
|
| 1795 |
-
/* ---- camera dropdown ---- */
|
| 1796 |
-
|
| 1797 |
-
/* 1) Fix overlap: make the Gradio HTML block shrink-to-fit when it contains a CameraDropdown.
|
| 1798 |
-
Gradio uses .gr-html for HTML components in most versions; older themes sometimes use .gradio-html.
|
| 1799 |
-
This keeps your big header HTML unaffected because it doesn't contain .cd-wrap.
|
| 1800 |
-
*/
|
| 1801 |
-
|
| 1802 |
-
/* 2) Actual dropdown layout */
|
| 1803 |
-
.cd-wrap{
|
| 1804 |
-
position: relative;
|
| 1805 |
-
display: inline-block;
|
| 1806 |
-
}
|
| 1807 |
-
|
| 1808 |
-
/* 3) Match RadioAnimated pill size/feel */
|
| 1809 |
-
.cd-trigger{
|
| 1810 |
-
margin-top: 2px;
|
| 1811 |
-
display: inline-flex;
|
| 1812 |
-
align-items: center;
|
| 1813 |
-
justify-content: center;
|
| 1814 |
-
gap: 10px;
|
| 1815 |
-
|
| 1816 |
-
border: none;
|
| 1817 |
-
|
| 1818 |
-
box-sizing: border-box;
|
| 1819 |
-
padding: 10px 18px;
|
| 1820 |
-
min-height: 52px;
|
| 1821 |
-
line-height: 1.2;
|
| 1822 |
-
|
| 1823 |
-
border-radius: 9999px;
|
| 1824 |
-
background: #0b0b0b;
|
| 1825 |
-
|
| 1826 |
-
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
|
| 1827 |
-
font-size: 14px;
|
| 1828 |
-
|
| 1829 |
-
/* ✅ match .ra-label exactly */
|
| 1830 |
-
color: rgba(255,255,255,0.7) !important;
|
| 1831 |
-
font-weight: 600 !important;
|
| 1832 |
-
|
| 1833 |
-
cursor: pointer;
|
| 1834 |
-
user-select: none;
|
| 1835 |
-
white-space: nowrap;
|
| 1836 |
-
}
|
| 1837 |
-
|
| 1838 |
-
/* Ensure inner spans match too */
|
| 1839 |
-
.cd-trigger .cd-trigger-text,
|
| 1840 |
-
.cd-trigger .cd-caret{
|
| 1841 |
-
color: rgba(255,255,255,0.7) !important;
|
| 1842 |
-
}
|
| 1843 |
-
|
| 1844 |
-
/* keep caret styling */
|
| 1845 |
-
.cd-caret{
|
| 1846 |
-
opacity: 0.8;
|
| 1847 |
-
font-weight: 900;
|
| 1848 |
-
}
|
| 1849 |
-
|
| 1850 |
-
/* 4) Ensure menu overlays neighbors and isn't clipped */
|
| 1851 |
-
/* Move dropdown a tiny bit up (closer to the trigger) */
|
| 1852 |
-
.cd-menu{
|
| 1853 |
-
position: absolute;
|
| 1854 |
-
top: calc(100% + 4px); /* was +10px */
|
| 1855 |
-
left: 0;
|
| 1856 |
-
|
| 1857 |
-
min-width: 240px;
|
| 1858 |
-
background: #2b2b2b;
|
| 1859 |
-
border: 1px solid rgba(255,255,255,0.14);
|
| 1860 |
-
border-radius: 14px;
|
| 1861 |
-
box-shadow: 0 18px 40px rgba(0,0,0,0.35);
|
| 1862 |
-
padding: 10px;
|
| 1863 |
-
|
| 1864 |
-
opacity: 0;
|
| 1865 |
-
transform: translateY(-6px);
|
| 1866 |
-
pointer-events: none;
|
| 1867 |
-
transition: opacity 160ms ease, transform 160ms ease;
|
| 1868 |
-
|
| 1869 |
-
z-index: 9999;
|
| 1870 |
-
}
|
| 1871 |
-
|
| 1872 |
-
.cd-title{
|
| 1873 |
-
font-size: 12px;
|
| 1874 |
-
font-weight: 600;
|
| 1875 |
-
text-transform: uppercase;
|
| 1876 |
-
letter-spacing: 0.04em;
|
| 1877 |
-
|
| 1878 |
-
color: rgba(255,255,255,0.45); /* 👈 muted grey */
|
| 1879 |
-
margin-bottom: 6px;
|
| 1880 |
-
padding: 0 6px;
|
| 1881 |
-
pointer-events: none; /* title is non-interactive */
|
| 1882 |
-
}
|
| 1883 |
-
|
| 1884 |
-
|
| 1885 |
-
.cd-menu.open{
|
| 1886 |
-
opacity: 1;
|
| 1887 |
-
transform: translateY(0);
|
| 1888 |
-
pointer-events: auto;
|
| 1889 |
-
}
|
| 1890 |
-
|
| 1891 |
-
.cd-items{
|
| 1892 |
-
display: flex;
|
| 1893 |
-
flex-direction: column;
|
| 1894 |
-
gap: 0px; /* tighter, more like a native menu */
|
| 1895 |
-
}
|
| 1896 |
-
|
| 1897 |
-
/* Items: NO "boxed" buttons by default */
|
| 1898 |
-
.cd-item{
|
| 1899 |
-
width: 100%;
|
| 1900 |
-
text-align: left;
|
| 1901 |
-
border: none;
|
| 1902 |
-
background: transparent; /* ✅ removes box look */
|
| 1903 |
-
color: rgba(255,255,255,0.92);
|
| 1904 |
-
padding: 8px 34px 8px 12px; /* right padding leaves room for tick */
|
| 1905 |
-
border-radius: 10px; /* only matters on hover */
|
| 1906 |
-
cursor: pointer;
|
| 1907 |
-
|
| 1908 |
-
font-size: 14px;
|
| 1909 |
-
font-weight: 700;
|
| 1910 |
-
|
| 1911 |
-
position: relative;
|
| 1912 |
-
transition: background 120ms ease;
|
| 1913 |
-
}
|
| 1914 |
-
|
| 1915 |
-
/* “Box effect” only on hover (not always) */
|
| 1916 |
-
.cd-item:hover{
|
| 1917 |
-
background: rgba(255,255,255,0.08);
|
| 1918 |
-
}
|
| 1919 |
-
|
| 1920 |
-
/* Tick on the right ONLY on hover */
|
| 1921 |
-
.cd-item::after{
|
| 1922 |
-
content: "✓";
|
| 1923 |
-
position: absolute;
|
| 1924 |
-
right: 12px;
|
| 1925 |
-
top: 50%;
|
| 1926 |
-
transform: translateY(-50%);
|
| 1927 |
-
opacity: 0; /* hidden by default */
|
| 1928 |
-
transition: opacity 120ms ease;
|
| 1929 |
-
color: rgba(255,255,255,0.9);
|
| 1930 |
-
font-weight: 900;
|
| 1931 |
}
|
| 1932 |
|
| 1933 |
-
/*
|
| 1934 |
-
|
| 1935 |
-
|
| 1936 |
-
}
|
|
|
|
|
|
|
| 1937 |
|
| 1938 |
-
/*
|
| 1939 |
-
.
|
| 1940 |
-
|
| 1941 |
-
}
|
| 1942 |
-
|
| 1943 |
-
|
| 1944 |
-
/* Kill any old “selected” styling just in case */
|
| 1945 |
-
.cd-item.selected{
|
| 1946 |
-
background: transparent !important;
|
| 1947 |
-
border: none !important;
|
| 1948 |
-
}
|
| 1949 |
-
|
| 1950 |
-
|
| 1951 |
-
"""
|
| 1952 |
-
|
| 1953 |
-
css += """
|
| 1954 |
-
/* icons in dropdown items */
|
| 1955 |
-
.cd-item{
|
| 1956 |
-
display: flex;
|
| 1957 |
-
align-items: center;
|
| 1958 |
-
gap: 10px;
|
| 1959 |
-
}
|
| 1960 |
-
.cd-icn{
|
| 1961 |
-
display: inline-flex;
|
| 1962 |
-
align-items: center;
|
| 1963 |
-
justify-content: center;
|
| 1964 |
-
width: 18px;
|
| 1965 |
-
height: 18px;
|
| 1966 |
-
flex: 0 0 18px;
|
| 1967 |
-
}
|
| 1968 |
-
.cd-label{
|
| 1969 |
-
flex: 1;
|
| 1970 |
-
}
|
| 1971 |
-
|
| 1972 |
-
/* =========================
|
| 1973 |
-
FIX: prompt border + scrollbar bleed
|
| 1974 |
-
========================= */
|
| 1975 |
-
|
| 1976 |
-
/* Put the border + background on the wrapper, not the textarea */
|
| 1977 |
-
.ds-top{
|
| 1978 |
-
position: relative;
|
| 1979 |
-
background: #2b2b2b;
|
| 1980 |
-
border: 1px solid rgba(255,255,255,0.12);
|
| 1981 |
-
border-radius: 14px;
|
| 1982 |
-
overflow: hidden; /* ensures the footer bar is clipped to rounded corners */
|
| 1983 |
-
}
|
| 1984 |
-
|
| 1985 |
-
/* Make textarea "transparent" so wrapper owns the border/background */
|
| 1986 |
-
.ds-textarea{
|
| 1987 |
-
background: transparent !important;
|
| 1988 |
-
border: none !important;
|
| 1989 |
-
border-radius: 0 !important; /* wrapper handles radius */
|
| 1990 |
-
outline: none;
|
| 1991 |
-
|
| 1992 |
-
/* keep your spacing */
|
| 1993 |
-
padding: 14px 16px;
|
| 1994 |
-
padding-bottom: 72px; /* room for footer */
|
| 1995 |
-
width: 100%;
|
| 1996 |
-
box-sizing: border-box;
|
| 1997 |
-
|
| 1998 |
-
/* keep scroll behavior */
|
| 1999 |
-
overflow-y: auto;
|
| 2000 |
-
|
| 2001 |
-
/* prevent scrollbar bleed by hiding native scrollbar */
|
| 2002 |
-
scrollbar-width: none; /* Firefox */
|
| 2003 |
-
}
|
| 2004 |
-
.ds-textarea::-webkit-scrollbar{ /* Chrome/Safari */
|
| 2005 |
-
width: 0;
|
| 2006 |
-
height: 0;
|
| 2007 |
-
}
|
| 2008 |
-
|
| 2009 |
-
/* Safe-area bar: now it matches perfectly because it's inside the same bordered wrapper */
|
| 2010 |
-
.ds-top::after{
|
| 2011 |
-
content: "";
|
| 2012 |
-
position: absolute;
|
| 2013 |
-
left: 0;
|
| 2014 |
-
right: 0;
|
| 2015 |
-
bottom: 0;
|
| 2016 |
-
height: 56px;
|
| 2017 |
-
background: #2b2b2b;
|
| 2018 |
-
pointer-events: none;
|
| 2019 |
-
z-index: 2;
|
| 2020 |
-
}
|
| 2021 |
-
|
| 2022 |
-
/* Footer above the bar */
|
| 2023 |
-
.ds-footer{
|
| 2024 |
-
position: absolute;
|
| 2025 |
-
right: 12px;
|
| 2026 |
-
bottom: 10px;
|
| 2027 |
-
display: flex;
|
| 2028 |
-
gap: 8px;
|
| 2029 |
-
align-items: center;
|
| 2030 |
-
justify-content: flex-end;
|
| 2031 |
-
z-index: 3;
|
| 2032 |
-
}
|
| 2033 |
-
|
| 2034 |
-
/* Ensure textarea content sits below overlays */
|
| 2035 |
-
.ds-textarea{
|
| 2036 |
-
position: relative;
|
| 2037 |
-
z-index: 1;
|
| 2038 |
-
}
|
| 2039 |
-
|
| 2040 |
-
/* ===== FIX dropdown menu being clipped/behind ===== */
|
| 2041 |
-
|
| 2042 |
-
/* Let the dropdown menu escape the prompt wrapper */
|
| 2043 |
-
.ds-top{
|
| 2044 |
-
overflow: visible !important; /* IMPORTANT: do not clip the menu */
|
| 2045 |
-
}
|
| 2046 |
-
|
| 2047 |
-
/* Keep the rounded "safe area" look without clipping the menu */
|
| 2048 |
-
.ds-top::after{
|
| 2049 |
-
left: 0 !important;
|
| 2050 |
-
right: 0 !important;
|
| 2051 |
-
bottom: 0 !important;
|
| 2052 |
-
border-bottom-left-radius: 14px !important;
|
| 2053 |
-
border-bottom-right-radius: 14px !important;
|
| 2054 |
-
}
|
| 2055 |
-
|
| 2056 |
-
/* Ensure the footer stays above the safe-area bar */
|
| 2057 |
-
.ds-footer{
|
| 2058 |
-
z-index: 20 !important;
|
| 2059 |
-
}
|
| 2060 |
-
|
| 2061 |
-
/* Make sure the opened menu is above EVERYTHING */
|
| 2062 |
-
.ds-footer .cd-menu{
|
| 2063 |
-
z-index: 999999 !important;
|
| 2064 |
-
}
|
| 2065 |
-
|
| 2066 |
-
/* Sometimes Gradio/columns/cards create stacking contexts;
|
| 2067 |
-
force the whole prompt card above nearby panels */
|
| 2068 |
-
.ds-card{
|
| 2069 |
-
position: relative;
|
| 2070 |
-
z-index: 50;
|
| 2071 |
-
}
|
| 2072 |
-
|
| 2073 |
-
/* --- Fix focus highlight shape (make it match rounded container) --- */
|
| 2074 |
-
|
| 2075 |
-
/* Kill any theme focus ring on the textarea itself */
|
| 2076 |
-
.ds-textarea:focus,
|
| 2077 |
-
.ds-textarea:focus-visible{
|
| 2078 |
-
outline: none !important;
|
| 2079 |
-
box-shadow: none !important;
|
| 2080 |
-
}
|
| 2081 |
-
|
| 2082 |
-
/* Optional: if some themes apply it even when not focused */
|
| 2083 |
-
.ds-textarea{
|
| 2084 |
-
outline: none !important;
|
| 2085 |
-
}
|
| 2086 |
-
|
| 2087 |
-
/* Apply the focus ring to the rounded wrapper instead */
|
| 2088 |
-
.ds-top:focus-within{
|
| 2089 |
-
border-color: rgba(255,255,255,0.22) !important;
|
| 2090 |
-
box-shadow: 0 0 0 3px rgba(255,255,255,0.06) !important;
|
| 2091 |
-
border-radius: 14px !important;
|
| 2092 |
-
}
|
| 2093 |
-
|
| 2094 |
-
/* If you see any tiny square corners, ensure the wrapper clips its own shadow properly */
|
| 2095 |
-
.ds-top{
|
| 2096 |
-
border-radius: 14px !important;
|
| 2097 |
-
}
|
| 2098 |
-
|
| 2099 |
-
/* =========================
|
| 2100 |
-
CameraDropdown: force readable menu text in BOTH themes
|
| 2101 |
-
========================= */
|
| 2102 |
-
|
| 2103 |
-
/* Menu surface */
|
| 2104 |
-
.cd-menu{
|
| 2105 |
-
background: #2b2b2b !important;
|
| 2106 |
-
border: 1px solid rgba(255,255,255,0.14) !important;
|
| 2107 |
-
}
|
| 2108 |
-
|
| 2109 |
-
/* Title */
|
| 2110 |
-
.cd-title{
|
| 2111 |
-
color: rgba(255,255,255,0.55) !important;
|
| 2112 |
-
}
|
| 2113 |
-
|
| 2114 |
-
/* Items + all descendants (fixes spans / inherited theme colors) */
|
| 2115 |
-
.cd-item,
|
| 2116 |
-
.cd-item *{
|
| 2117 |
-
color: rgba(255,255,255,0.92) !important;
|
| 2118 |
-
}
|
| 2119 |
-
|
| 2120 |
-
/* Hover state */
|
| 2121 |
-
.cd-item:hover{
|
| 2122 |
-
background: rgba(255,255,255,0.10) !important;
|
| 2123 |
-
}
|
| 2124 |
-
|
| 2125 |
-
/* Checkmark */
|
| 2126 |
-
.cd-item::after{
|
| 2127 |
-
color: rgba(255,255,255,0.92) !important;
|
| 2128 |
-
}
|
| 2129 |
-
|
| 2130 |
-
/* (Optional) make sure the trigger stays readable too */
|
| 2131 |
-
.cd-trigger,
|
| 2132 |
-
.cd-trigger *{
|
| 2133 |
-
color: rgba(255,255,255,0.75) !important;
|
| 2134 |
-
}
|
| 2135 |
-
|
| 2136 |
-
/* ---- preset gallery ---- */
|
| 2137 |
-
.pg-wrap{
|
| 2138 |
-
width: 100%;
|
| 2139 |
-
max-width: 1100px;
|
| 2140 |
-
margin: 18px auto 0 auto;
|
| 2141 |
-
}
|
| 2142 |
-
.pg-title{
|
| 2143 |
-
text-align: center;
|
| 2144 |
-
margin-bottom: 14px;
|
| 2145 |
-
}
|
| 2146 |
-
.pg-h1{
|
| 2147 |
-
font-size: 34px;
|
| 2148 |
-
font-weight: 800;
|
| 2149 |
-
line-height: 1.1;
|
| 2150 |
-
|
| 2151 |
-
/* ✅ theme-aware */
|
| 2152 |
-
color: var(--body-text-color);
|
| 2153 |
-
}
|
| 2154 |
-
.pg-h2{
|
| 2155 |
-
font-size: 14px;
|
| 2156 |
-
font-weight: 600;
|
| 2157 |
-
color: var(--body-text-color-subdued);
|
| 2158 |
-
margin-top: 6px;
|
| 2159 |
-
}
|
| 2160 |
-
|
| 2161 |
-
.pg-grid{
|
| 2162 |
-
display: grid;
|
| 2163 |
-
grid-template-columns: repeat(3, minmax(0, 1fr)); /* 3 per row */
|
| 2164 |
-
gap: 18px;
|
| 2165 |
-
}
|
| 2166 |
-
|
| 2167 |
-
.pg-card{
|
| 2168 |
-
border: none;
|
| 2169 |
-
background: transparent;
|
| 2170 |
-
padding: 0;
|
| 2171 |
-
cursor: pointer;
|
| 2172 |
-
border-radius: 12px;
|
| 2173 |
-
overflow: hidden;
|
| 2174 |
-
position: relative;
|
| 2175 |
-
transform: translateZ(0);
|
| 2176 |
-
}
|
| 2177 |
-
|
| 2178 |
-
.pg-img{
|
| 2179 |
-
width: 100%;
|
| 2180 |
-
height: 220px; /* adjust to match your look */
|
| 2181 |
-
object-fit: cover;
|
| 2182 |
-
display: block;
|
| 2183 |
-
border-radius: 12px;
|
| 2184 |
-
transition: transform 160ms ease, filter 160ms ease, opacity 160ms ease;
|
| 2185 |
-
}
|
| 2186 |
-
|
| 2187 |
-
/* hover: slight zoom on hovered card */
|
| 2188 |
-
.pg-card:hover .pg-img{
|
| 2189 |
-
transform: scale(1.02);
|
| 2190 |
-
}
|
| 2191 |
-
|
| 2192 |
-
/* dim others while hovering */
|
| 2193 |
-
.pg-card[data-dim="true"] .pg-img{
|
| 2194 |
-
opacity: 0.35;
|
| 2195 |
-
filter: saturate(0.9);
|
| 2196 |
-
}
|
| 2197 |
-
|
| 2198 |
-
/* keep hovered/active crisp */
|
| 2199 |
-
.pg-card[data-active="true"] .pg-img{
|
| 2200 |
-
opacity: 1.0;
|
| 2201 |
-
filter: none;
|
| 2202 |
-
}
|
| 2203 |
-
|
| 2204 |
-
|
| 2205 |
-
"""
|
| 2206 |
-
|
| 2207 |
-
|
| 2208 |
-
css += """
|
| 2209 |
-
/* ---- AudioDropUpload ---- */
|
| 2210 |
-
.aud-wrap{
|
| 2211 |
-
width: 100%;
|
| 2212 |
-
max-width: 720px;
|
| 2213 |
-
}
|
| 2214 |
-
.aud-drop{
|
| 2215 |
-
border: 2px dashed var(--body-text-color-subdued);
|
| 2216 |
-
border-radius: 16px;
|
| 2217 |
-
padding: 18px;
|
| 2218 |
-
text-align: center;
|
| 2219 |
-
cursor: pointer;
|
| 2220 |
-
user-select: none;
|
| 2221 |
-
color: var(--body-text-color);
|
| 2222 |
-
background: var(--block-background-fill);
|
| 2223 |
-
}
|
| 2224 |
-
.aud-drop.dragover{
|
| 2225 |
-
border-color: rgba(255,255,255,0.35);
|
| 2226 |
-
background: rgba(255,255,255,0.06);
|
| 2227 |
-
}
|
| 2228 |
-
.aud-hint{
|
| 2229 |
-
color: var(--body-text-color-subdued);
|
| 2230 |
-
font-size: 0.95rem;
|
| 2231 |
-
margin-top: 6px;
|
| 2232 |
-
}
|
| 2233 |
-
/* pill row like your other controls */
|
| 2234 |
-
.aud-row{
|
| 2235 |
-
display: none;
|
| 2236 |
-
align-items: center;
|
| 2237 |
-
gap: 10px;
|
| 2238 |
-
background: #0b0b0b;
|
| 2239 |
-
border-radius: 9999px;
|
| 2240 |
-
padding: 8px 10px;
|
| 2241 |
-
}
|
| 2242 |
-
.aud-player{
|
| 2243 |
-
flex: 1;
|
| 2244 |
-
width: 100%;
|
| 2245 |
-
height: 34px;
|
| 2246 |
-
border-radius: 9999px;
|
| 2247 |
-
}
|
| 2248 |
-
.aud-remove{
|
| 2249 |
-
appearance: none;
|
| 2250 |
-
border: none;
|
| 2251 |
-
background: transparent;
|
| 2252 |
-
color: rgba(255,255,255);
|
| 2253 |
-
cursor: pointer;
|
| 2254 |
-
width: 36px;
|
| 2255 |
-
height: 36px;
|
| 2256 |
-
border-radius: 9999px;
|
| 2257 |
-
display: inline-flex;
|
| 2258 |
-
align-items: center;
|
| 2259 |
-
justify-content: center;
|
| 2260 |
-
padding: 0;
|
| 2261 |
-
transition: background 120ms ease, color 120ms ease, opacity 120ms ease;
|
| 2262 |
-
opacity: 0.9;
|
| 2263 |
-
flex: 0 0 auto;
|
| 2264 |
-
}
|
| 2265 |
-
.aud-remove:hover{
|
| 2266 |
-
background: rgba(255,255,255,0.08);
|
| 2267 |
-
color: rgb(255,255,255);
|
| 2268 |
-
opacity: 1;
|
| 2269 |
-
}
|
| 2270 |
-
.aud-filelabel{
|
| 2271 |
-
margin: 10px 6px 0;
|
| 2272 |
-
color: var(--body-text-color-subdued);
|
| 2273 |
-
font-size: 0.95rem;
|
| 2274 |
-
display: none;
|
| 2275 |
-
}
|
| 2276 |
-
#audio_input_hidden { display: none !important; }
|
| 2277 |
-
"""
|
| 2278 |
-
|
| 2279 |
-
# Hiding Gradio Footer, Branding and Settings
|
| 2280 |
-
css += """
|
| 2281 |
-
footer {
|
| 2282 |
-
display: none !important;
|
| 2283 |
-
}
|
| 2284 |
-
.gradio-container footer {
|
| 2285 |
-
display: none !important;
|
| 2286 |
-
}
|
| 2287 |
-
div.footer {
|
| 2288 |
-
display: none !important;
|
| 2289 |
-
}
|
| 2290 |
-
.flagging {
|
| 2291 |
-
display: none !important;
|
| 2292 |
-
}
|
| 2293 |
-
/* Hide the 'Use via API' link if visible */
|
| 2294 |
-
.api-logo, .built-with {
|
| 2295 |
-
display: none !important;
|
| 2296 |
-
}
|
| 2297 |
"""
|
| 2298 |
|
| 2299 |
# --- MODAL CSS Injection ---
|
| 2300 |
css += """
|
| 2301 |
-
/* Modal CSS
|
| 2302 |
:root { --guide-bg: rgba(255, 255, 255, 0.98); --guide-border: rgba(102, 126, 234, 0.2); --guide-text-title: #2d3748; --guide-text-body: #4a5568; --guide-accent: #667eea; --primary-gradient-guide: linear-gradient(135deg, #667eea 0%, #764ba2 100%); --success-gradient-guide: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%); --radius-md-guide: 12px; --radius-lg-guide: 16px; --shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07), 0 8px 10px -6px rgba(26, 32, 44, 0.05); }
|
| 2303 |
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-10px); } }
|
| 2304 |
@keyframes slideInUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
|
|
@@ -2335,82 +873,21 @@ css += """
|
|
| 2335 |
"""
|
| 2336 |
|
| 2337 |
def apply_example(idx: str):
|
| 2338 |
-
|
| 2339 |
-
|
| 2340 |
-
#
|
| 2341 |
-
|
| 2342 |
-
|
| 2343 |
-
img_path = img if img else None
|
| 2344 |
-
vid_path = vid if vid else None
|
| 2345 |
-
aud_path = aud if aud else None
|
| 2346 |
-
|
| 2347 |
-
input_image_update = img_path
|
| 2348 |
-
prompt_update = prompt_txt
|
| 2349 |
-
camera_update = cam
|
| 2350 |
-
resolution_update = res
|
| 2351 |
-
mode_update = mode
|
| 2352 |
-
video_update = gr.update(value=vid_path, visible=(mode == "Motion Control"))
|
| 2353 |
-
audio_update = aud_path
|
| 2354 |
-
end_image = end_img
|
| 2355 |
-
|
| 2356 |
-
return (
|
| 2357 |
-
input_image_update,
|
| 2358 |
-
prompt_update,
|
| 2359 |
-
camera_update,
|
| 2360 |
-
resolution_update,
|
| 2361 |
-
mode_update,
|
| 2362 |
-
video_update,
|
| 2363 |
-
audio_update,
|
| 2364 |
-
audio_update,
|
| 2365 |
-
end_image,
|
| 2366 |
-
)
|
| 2367 |
|
|
|
|
|
|
|
| 2368 |
|
| 2369 |
####################################################################################################
|
| 2370 |
### PART 20: Gradio UI Layout & Launch
|
| 2371 |
####################################################################################################
|
| 2372 |
-
def apply_example(idx: str):
|
| 2373 |
-
idx = int(idx)
|
| 2374 |
-
|
| 2375 |
-
# Read the example row from your list
|
| 2376 |
-
img, prompt_txt, cam, res, mode, vid, aud, end_img = examples_list[idx]
|
| 2377 |
-
|
| 2378 |
-
img_path = img if img else None
|
| 2379 |
-
vid_path = vid if vid else None
|
| 2380 |
-
aud_path = aud if aud else None
|
| 2381 |
-
|
| 2382 |
-
input_image_update = img_path
|
| 2383 |
-
prompt_update = prompt_txt
|
| 2384 |
-
camera_update = cam
|
| 2385 |
-
resolution_update = res
|
| 2386 |
-
mode_update = mode
|
| 2387 |
-
video_update = gr.update(value=vid_path, visible=(mode == "Motion Control"))
|
| 2388 |
-
audio_update = aud_path
|
| 2389 |
-
end_image = end_img
|
| 2390 |
-
|
| 2391 |
-
# Clear the output video when loading a new example
|
| 2392 |
-
output_video_update = gr.update(value=None)
|
| 2393 |
-
|
| 2394 |
-
return (
|
| 2395 |
-
input_image_update,
|
| 2396 |
-
prompt_update,
|
| 2397 |
-
camera_update,
|
| 2398 |
-
resolution_update,
|
| 2399 |
-
mode_update,
|
| 2400 |
-
video_update,
|
| 2401 |
-
audio_update,
|
| 2402 |
-
audio_update,
|
| 2403 |
-
end_image,
|
| 2404 |
-
output_video_update
|
| 2405 |
-
)
|
| 2406 |
-
|
| 2407 |
|
| 2408 |
with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
|
| 2409 |
|
| 2410 |
# --- JS QUOTA HANDLER ---
|
| 2411 |
-
# Injected Logic from Fusion Space adapted for Video Space
|
| 2412 |
-
# Looks for 'quota' errors, hides them, shows modal.
|
| 2413 |
-
# Retry button clicks #generate-btn
|
| 2414 |
js_quota_handler = """
|
| 2415 |
<script>
|
| 2416 |
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -2532,33 +1009,30 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
|
|
| 2532 |
|
| 2533 |
gr.HTML(js_quota_handler)
|
| 2534 |
|
| 2535 |
-
#
|
| 2536 |
gr.HTML(
|
| 2537 |
"""
|
| 2538 |
-
<div
|
| 2539 |
-
<h1
|
| 2540 |
-
|
| 2541 |
-
</h1>
|
| 2542 |
-
<p style="font-size: 18px; color: var(--body-text-color-subdued); margin: 0;">
|
| 2543 |
-
با پشتیبانی از صدا و دو تصویر
|
| 2544 |
-
</p>
|
| 2545 |
</div>
|
| 2546 |
"""
|
| 2547 |
)
|
| 2548 |
|
| 2549 |
with gr.Column(elem_id="col-container"):
|
| 2550 |
-
with gr.Row(
|
| 2551 |
-
#
|
| 2552 |
-
|
| 2553 |
choices=["تبدیل تصویر به ویدیو", "تکمیل فریمهای میانی"],
|
| 2554 |
value="تبدیل تصویر به ویدیو",
|
| 2555 |
-
|
|
|
|
| 2556 |
)
|
|
|
|
| 2557 |
with gr.Row():
|
| 2558 |
with gr.Column(elem_id="step-column"):
|
| 2559 |
|
| 2560 |
with gr.Row():
|
| 2561 |
-
|
| 2562 |
first_frame = gr.Image(
|
| 2563 |
label="تصویر اول (اختیاری)",
|
| 2564 |
type="filepath",
|
|
@@ -2572,82 +1046,34 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
|
|
| 2572 |
visible=False,
|
| 2573 |
)
|
| 2574 |
|
| 2575 |
-
# input_video is defined but hidden
|
| 2576 |
input_video = gr.Video(
|
| 2577 |
label="Motion Reference Video",
|
| 2578 |
height=256,
|
| 2579 |
visible=False,
|
| 2580 |
)
|
| 2581 |
|
| 2582 |
-
|
| 2583 |
-
value="",
|
| 2584 |
-
html_template="<div></div>",
|
| 2585 |
-
js_on_load=r"""
|
| 2586 |
-
(() => {
|
| 2587 |
-
function moveIntoFooter() {
|
| 2588 |
-
const promptRoot = document.querySelector("#prompt_ui");
|
| 2589 |
-
if (!promptRoot) return false;
|
| 2590 |
-
|
| 2591 |
-
const footer = promptRoot.querySelector(".ds-footer");
|
| 2592 |
-
if (!footer) return false;
|
| 2593 |
-
|
| 2594 |
-
const dur = document.querySelector("#duration_ui .cd-wrap");
|
| 2595 |
-
const res = document.querySelector("#resolution_ui .cd-wrap");
|
| 2596 |
-
const cam = document.querySelector("#camera_ui .cd-wrap");
|
| 2597 |
-
|
| 2598 |
-
if (!dur || !res || !cam) return false;
|
| 2599 |
-
|
| 2600 |
-
footer.appendChild(dur);
|
| 2601 |
-
footer.appendChild(res);
|
| 2602 |
-
footer.appendChild(cam);
|
| 2603 |
-
|
| 2604 |
-
return true;
|
| 2605 |
-
}
|
| 2606 |
-
|
| 2607 |
-
const tick = () => {
|
| 2608 |
-
if (!moveIntoFooter()) requestAnimationFrame(tick);
|
| 2609 |
-
};
|
| 2610 |
-
requestAnimationFrame(tick);
|
| 2611 |
-
})();
|
| 2612 |
-
"""
|
| 2613 |
-
)
|
| 2614 |
-
|
| 2615 |
-
|
| 2616 |
-
prompt_ui = PromptBox(
|
| 2617 |
-
value="این تصویر را با حرکت سینمایی و انیمیشن روان زنده کن",
|
| 2618 |
-
elem_id="prompt_ui",
|
| 2619 |
-
)
|
| 2620 |
-
|
| 2621 |
-
# Hidden real audio input (backend value)
|
| 2622 |
-
audio_input = gr.File(
|
| 2623 |
-
label="Audio (Optional)",
|
| 2624 |
-
file_types=["audio"],
|
| 2625 |
-
type="filepath",
|
| 2626 |
-
elem_id="audio_input_hidden",
|
| 2627 |
-
)
|
| 2628 |
-
|
| 2629 |
-
# Custom UI that feeds the hidden gr.Audio above
|
| 2630 |
-
audio_ui = AudioDropUpload(
|
| 2631 |
-
target_audio_elem_id="audio_input_hidden",
|
| 2632 |
-
elem_id="audio_ui",
|
| 2633 |
-
)
|
| 2634 |
-
|
| 2635 |
prompt = gr.Textbox(
|
| 2636 |
-
label="Prompt",
|
| 2637 |
value="این تصویر را با حرکت سینمایی و انیمیشن روان زنده کن",
|
| 2638 |
lines=3,
|
| 2639 |
-
max_lines=3,
|
| 2640 |
placeholder="حرکت و انیمیشن مورد نظر خود را توصیف کنید...",
|
| 2641 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2642 |
)
|
| 2643 |
|
| 2644 |
enhance_prompt = gr.Checkbox(
|
| 2645 |
-
label="Enhance Prompt",
|
| 2646 |
value=True,
|
| 2647 |
visible=False
|
| 2648 |
)
|
| 2649 |
|
| 2650 |
-
with gr.Accordion("تنظیمات پیشرفته", open=False
|
| 2651 |
seed = gr.Slider(
|
| 2652 |
label="سید (Seed)",
|
| 2653 |
minimum=0,
|
|
@@ -2662,105 +1088,64 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
|
|
| 2662 |
with gr.Column(elem_id="step-column"):
|
| 2663 |
output_video = gr.Video(label="ویدیوی ساخته شده", autoplay=True, height=512)
|
| 2664 |
|
| 2665 |
-
with gr.Row(
|
| 2666 |
-
|
| 2667 |
-
|
| 2668 |
choices=["3s", "5s", "10s"],
|
| 2669 |
value="5s",
|
| 2670 |
-
|
| 2671 |
-
|
| 2672 |
)
|
| 2673 |
-
|
| 2674 |
-
duration = gr.Slider(
|
| 2675 |
-
label="Duration (seconds)",
|
| 2676 |
-
minimum=1.0,
|
| 2677 |
-
maximum=10.0,
|
| 2678 |
-
value=5.0,
|
| 2679 |
-
step=0.1,
|
| 2680 |
-
visible=False
|
| 2681 |
-
)
|
| 2682 |
-
|
| 2683 |
-
ICON_16_9 = """<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
| 2684 |
-
<rect x="3" y="7" width="18" height="10" rx="2" stroke="currentColor" stroke-width="2"/>
|
| 2685 |
-
</svg>"""
|
| 2686 |
-
|
| 2687 |
-
ICON_1_1 = """<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
| 2688 |
-
<rect x="6" y="6" width="12" height="12" rx="2" stroke="currentColor" stroke-width="2"/>
|
| 2689 |
-
</svg>"""
|
| 2690 |
-
|
| 2691 |
-
ICON_9_16 = """<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
| 2692 |
-
<rect x="7" y="3" width="10" height="18" rx="2" stroke="currentColor" stroke-width="2"/>
|
| 2693 |
-
</svg>"""
|
| 2694 |
-
|
| 2695 |
|
| 2696 |
-
|
| 2697 |
-
choices=[
|
| 2698 |
-
{"label": "16:9", "value": "16:9", "icon": ICON_16_9},
|
| 2699 |
-
{"label": "1:1", "value": "1:1", "icon": ICON_1_1},
|
| 2700 |
-
{"label": "9:16", "value": "9:16", "icon": ICON_9_16},
|
| 2701 |
-
],
|
| 2702 |
value="16:9",
|
| 2703 |
-
|
| 2704 |
-
|
| 2705 |
)
|
| 2706 |
|
| 2707 |
-
|
| 2708 |
-
width = gr.Number(label="Width", value=DEFAULT_1_STAGE_WIDTH, precision=0, visible=False)
|
| 2709 |
-
height = gr.Number(label="Height", value=DEFAULT_1_STAGE_HEIGHT, precision=0, visible=False)
|
| 2710 |
-
|
| 2711 |
-
camera_ui = CameraDropdown(
|
| 2712 |
choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES],
|
| 2713 |
value="No LoRA",
|
| 2714 |
-
|
| 2715 |
-
|
| 2716 |
-
)
|
| 2717 |
-
|
| 2718 |
-
# Hidden real dropdown (backend value)
|
| 2719 |
-
camera_lora = gr.Dropdown(
|
| 2720 |
-
label="Camera Control LoRA",
|
| 2721 |
-
choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES],
|
| 2722 |
-
value="No LoRA",
|
| 2723 |
-
visible=False
|
| 2724 |
)
|
| 2725 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2726 |
# IMPORTANT: Added elem_id="generate-btn" for JS control
|
| 2727 |
generate_btn = gr.Button("🤩 ساخت ویدیو", variant="primary", elem_classes="button-gradient", elem_id="generate-btn")
|
| 2728 |
|
| 2729 |
|
| 2730 |
-
|
| 2731 |
-
|
| 2732 |
-
|
| 2733 |
-
|
| 2734 |
-
|
| 2735 |
-
|
| 2736 |
-
|
| 2737 |
-
|
| 2738 |
-
|
| 2739 |
-
|
| 2740 |
-
outputs=[input_video, end_frame],
|
| 2741 |
-
api_visibility="private",
|
| 2742 |
)
|
| 2743 |
|
|
|
|
|
|
|
| 2744 |
|
| 2745 |
-
|
| 2746 |
-
fn=
|
| 2747 |
-
inputs=
|
| 2748 |
-
outputs=[
|
| 2749 |
-
api_visibility="private"
|
| 2750 |
-
)
|
| 2751 |
-
resolution_ui.change(
|
| 2752 |
-
fn=apply_resolution,
|
| 2753 |
-
inputs=resolution_ui,
|
| 2754 |
-
outputs=[width, height],
|
| 2755 |
-
api_visibility="private"
|
| 2756 |
-
)
|
| 2757 |
-
prompt_ui.change(
|
| 2758 |
-
fn=lambda x: x,
|
| 2759 |
-
inputs=prompt_ui,
|
| 2760 |
-
outputs=prompt,
|
| 2761 |
-
api_visibility="private"
|
| 2762 |
)
|
| 2763 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2764 |
|
| 2765 |
generate_btn.click(
|
| 2766 |
fn=generate_video,
|
|
@@ -2768,137 +1153,70 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
|
|
| 2768 |
first_frame,
|
| 2769 |
end_frame,
|
| 2770 |
prompt,
|
| 2771 |
-
|
| 2772 |
input_video,
|
| 2773 |
-
|
| 2774 |
enhance_prompt,
|
| 2775 |
seed,
|
| 2776 |
randomize_seed,
|
| 2777 |
height,
|
| 2778 |
width,
|
| 2779 |
-
|
| 2780 |
audio_input
|
| 2781 |
],
|
| 2782 |
outputs=[output_video]
|
| 2783 |
)
|
| 2784 |
|
| 2785 |
-
#
|
| 2786 |
examples_list = [
|
| 2787 |
[
|
| 2788 |
"examples/supergirl-2.png",
|
| 2789 |
-
|
|
|
|
| 2790 |
"Static",
|
| 2791 |
"16:9",
|
| 2792 |
"تبدیل تصویر به ویدیو",
|
| 2793 |
-
None,
|
| 2794 |
"examples/supergirl.m4a",
|
| 2795 |
-
None,
|
| 2796 |
],
|
| 2797 |
[
|
| 2798 |
"examples/frame3.png",
|
| 2799 |
-
"
|
|
|
|
| 2800 |
"Zoom In",
|
| 2801 |
"16:9",
|
| 2802 |
"تکمیل فریمهای میانی",
|
| 2803 |
None,
|
| 2804 |
-
None,
|
| 2805 |
-
"examples/frame4.png",
|
| 2806 |
],
|
| 2807 |
[
|
| 2808 |
"examples/supergirl.png",
|
| 2809 |
-
"A fuzzy puppet superhero character resembling a female puppet with blonde hair and a blue superhero suit stands inside an icy cave made of frozen walls and icicles, she looks panicked and frantic, rapidly turning her head left and right and scanning the cave while waving her arms and shouting angrily and desperately, mouthing the words “where the hell is my dog,” her movements exaggerated and puppet-like with high energy and urgency, suddenly a second puppet dog bursts into frame from the side, jumping up excitedly and tackling her affectionately while licking her face repeatedly, she freezes in surprise and then breaks into relief and laughter as the dog continues licking her, the scene feels chaotic, comedic, and emotional with expressive puppet reactions, cinematic lighting, smooth camera motion, shallow depth of field, and high-quality puppet-style animation",
|
| 2810 |
-
"No LoRA",
|
| 2811 |
-
"16:9",
|
| 2812 |
-
"تبدیل تصویر به ویدیو",
|
| 2813 |
-
None,
|
| 2814 |
-
None,
|
| 2815 |
None,
|
| 2816 |
-
|
| 2817 |
-
[
|
| 2818 |
-
"examples/highland.png",
|
| 2819 |
-
"Realistic POV selfie-style video in a snowy, foggy field. Two shaggy Highland cows with long curved horns stand ahead. The camera is handheld and slightly shaky. The woman filming talks nervously and excitedly in a vlog tone: \"Oh my god guys… look how big those horns are… I’m kinda scared.\" The cow on the left walks toward the camera in a cute, bouncy, hopping way, curious and gentle. Snow crunches under its hooves, breath visible in the cold air. The horns look massive from the POV. As the cow gets very close, its wet nose with slight dripping fills part of the frame. She laughs nervously but reaches out and pets the cow. The cow makes deep, soft, interesting mooing and snorting sounds, calm and friendly. Ultra-realistic, natural lighting, immersive audio, documentary-style realism.",
|
| 2820 |
"No LoRA",
|
| 2821 |
"16:9",
|
| 2822 |
"تبدیل تصویر به ویدیو",
|
| 2823 |
None,
|
| 2824 |
-
None,
|
| 2825 |
-
None,
|
| 2826 |
],
|
| 2827 |
[
|
| 2828 |
"examples/wednesday.png",
|
| 2829 |
-
"A cinematic dolly out of Wednesday Addams frozen mid-dance on a dark, blue-lit ballroom floor as students move indistinctly behind her, their footsteps and muffled music reduced to a distant, underwater thrum; the audio foregrounds her steady breathing and the faint rustle of fabric as she slowly raises one arm, never breaking eye contact with the camera, then after a deliberately long silence she speaks in a flat, dry, perfectly controlled voice, “I don’t dance… I vibe code,” each word crisp and unemotional, followed by an abrupt cutoff of her voice as the background sound swells slightly, reinforcing the deadpan humor, with precise lip sync, minimal facial movement, stark gothic lighting, and cinematic realism.",
|
| 2830 |
-
"Zoom Out",
|
| 2831 |
-
"16:9",
|
| 2832 |
-
"تبدیل تصویر به ویدیو",
|
| 2833 |
-
None,
|
| 2834 |
-
None,
|
| 2835 |
None,
|
| 2836 |
-
|
| 2837 |
-
|
| 2838 |
-
"
|
| 2839 |
-
"An astronaut hatches from a fragile egg on the surface of the Moon, the shell cracking and peeling apart in gentle low-gravity motion. Fine lunar dust lifts and drifts outward with each movement, floating in slow arcs before settling back onto the ground. The astronaut pushes free in a deliberate, weightless motion, small fragments of the egg tumbling and spinning through the air. In the background, the deep darkness of space subtly shifts as stars glide with the camera's movement, emphasizing vast depth and scale. The camera performs a smooth, cinematic slow push-in, with natural parallax between the foreground dust, the astronaut, and the distant starfield. Ultra-realistic detail, physically accurate low-gravity motion, cinematic lighting, and a breath-taking, movie-like shot.",
|
| 2840 |
-
"Static",
|
| 2841 |
-
"1:1",
|
| 2842 |
"تبدیل تصویر به ویدیو",
|
| 2843 |
None,
|
| 2844 |
-
|
| 2845 |
-
None,
|
| 2846 |
-
],
|
| 2847 |
]
|
| 2848 |
|
| 2849 |
-
|
| 2850 |
-
|
| 2851 |
-
|
| 2852 |
-
inputs=[first_frame, prompt_ui, camera_ui, resolution_ui, radioanimated_mode, input_video, audio_input, end_frame],
|
| 2853 |
-
outputs = [output_video],
|
| 2854 |
-
label="نمونهها",
|
| 2855 |
-
cache_examples=True,
|
| 2856 |
-
visible=False
|
| 2857 |
-
)
|
| 2858 |
-
|
| 2859 |
-
preset_gallery = PresetGallery(
|
| 2860 |
-
items=[
|
| 2861 |
-
{"thumb": "examples/supergirl-2.png", "label": "تصویر و صدا به ویدیو"},
|
| 2862 |
-
{"thumb": "examples/frame3.png", "label": "تصویر اول و آخر"},
|
| 2863 |
-
{"thumb": "examples/supergirl.png", "label": "تصویر به ویدیو (عروسک)"},
|
| 2864 |
-
{"thumb": "examples/highland.png", "label": "تصویر به ویدیو (گاو)"},
|
| 2865 |
-
{"thumb": "examples/wednesday.png", "label": "تصویر به ویدیو (ونزدی)"},
|
| 2866 |
-
{"thumb": "examples/astronaut.png", "label": "تصویر به ویدیو (فضانورد)"},
|
| 2867 |
-
],
|
| 2868 |
-
title="برای شروع روی یکی از نمونهها کلیک کنید",
|
| 2869 |
-
)
|
| 2870 |
-
|
| 2871 |
-
def on_audio_ui_change(v):
|
| 2872 |
-
# Our JS sends "__CLEAR__" when the user presses the X
|
| 2873 |
-
if v == "__CLEAR__" or v is None or v == "":
|
| 2874 |
-
return None
|
| 2875 |
-
# For normal events (uploads), do nothing (keep whatever gr.File already has)
|
| 2876 |
-
return gr.update()
|
| 2877 |
|
| 2878 |
-
|
| 2879 |
-
|
| 2880 |
-
|
| 2881 |
-
|
| 2882 |
-
|
| 2883 |
-
)
|
| 2884 |
-
|
| 2885 |
-
preset_gallery.change(
|
| 2886 |
-
fn=apply_example,
|
| 2887 |
-
inputs=preset_gallery,
|
| 2888 |
-
outputs=[
|
| 2889 |
-
first_frame,
|
| 2890 |
-
prompt_ui,
|
| 2891 |
-
camera_ui,
|
| 2892 |
-
resolution_ui,
|
| 2893 |
-
radioanimated_mode,
|
| 2894 |
-
input_video,
|
| 2895 |
-
audio_input,
|
| 2896 |
-
audio_ui,
|
| 2897 |
-
end_frame,
|
| 2898 |
-
output_video # Clears the output video
|
| 2899 |
-
],
|
| 2900 |
-
api_visibility="private",
|
| 2901 |
)
|
| 2902 |
|
| 2903 |
if __name__ == "__main__":
|
| 2904 |
-
demo.launch(ssr_mode=False,
|
|
|
|
| 34 |
|
| 35 |
# pathlib.Path etc.
|
| 36 |
if not isinstance(audio_path, (str, bytes, os.PathLike)):
|
| 37 |
+
# Allow None
|
| 38 |
+
if audio_path is None: return None
|
| 39 |
raise TypeError(f"audio_path must be a path-like, got {type(audio_path)}: {audio_path}")
|
| 40 |
|
| 41 |
return os.fspath(audio_path)
|
|
|
|
| 91 |
Load audio, resample, (optionally) mono, then trim/pad to exactly target_seconds.
|
| 92 |
Returns: (waveform[T] or [1,T], sr)
|
| 93 |
"""
|
| 94 |
+
if audio_path is None:
|
| 95 |
+
return None, None
|
| 96 |
+
|
| 97 |
audio_path = _coerce_audio_path(audio_path)
|
| 98 |
|
| 99 |
wav, sr = torchaudio.load(audio_path) # [C, T] float32 CPU
|
|
|
|
| 552 |
print("=" * 80)
|
| 553 |
|
| 554 |
|
|
|
|
|
|
|
|
|
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################################################################################
|
| 556 |
### PART 17: Wrapper Functions (Resolution, Duration, Examples)
|
| 557 |
####################################################################################################
|
|
|
|
| 779 |
return int(w), int(h)
|
| 780 |
|
| 781 |
def apply_duration(duration: str):
|
| 782 |
+
# Standard format: "5s"
|
| 783 |
+
try:
|
| 784 |
+
duration_s = int(str(duration).replace("s", ""))
|
| 785 |
+
except:
|
| 786 |
+
duration_s = 5
|
| 787 |
return duration_s
|
| 788 |
|
| 789 |
def on_mode_change(selected: str):
|
|
|
|
| 798 |
### PART 19: CSS Styles
|
| 799 |
####################################################################################################
|
| 800 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
#col-container {
|
| 802 |
margin: 0 auto;
|
| 803 |
max-width: 1600px;
|
| 804 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 805 |
.button-gradient {
|
| 806 |
background: linear-gradient(45deg, rgb(255, 65, 108), rgb(255, 75, 43), rgb(255, 155, 0), rgb(255, 65, 108)) 0% 0% / 400% 400%;
|
| 807 |
border: none;
|
|
|
|
| 815 |
animation: 2s linear 0s infinite normal none running gradientAnimation;
|
| 816 |
box-shadow: rgba(255, 65, 108, 0.6) 0px 4px 10px;
|
| 817 |
}
|
| 818 |
+
@keyframes gradientAnimation {
|
| 819 |
+
0% { background-position: 0% 50%; }
|
| 820 |
+
50% { background-position: 100% 50%; }
|
| 821 |
+
100% { background-position: 0% 50%; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
}
|
| 823 |
|
| 824 |
+
/* Footer Hiding */
|
| 825 |
+
footer { display: none !important; }
|
| 826 |
+
.gradio-container footer { display: none !important; }
|
| 827 |
+
div.footer { display: none !important; }
|
| 828 |
+
.flagging { display: none !important; }
|
| 829 |
+
.api-logo, .built-with { display: none !important; }
|
| 830 |
|
| 831 |
+
/* Center Title */
|
| 832 |
+
.title-container { text-align: center; padding: 20px; }
|
| 833 |
+
.title-text { font-size: 28px; font-weight: bold; margin-bottom: 10px; color: var(--body-text-color); }
|
| 834 |
+
.subtitle-text { font-size: 18px; color: var(--body-text-color-subdued); margin: 0; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 835 |
"""
|
| 836 |
|
| 837 |
# --- MODAL CSS Injection ---
|
| 838 |
css += """
|
| 839 |
+
/* Modal CSS */
|
| 840 |
:root { --guide-bg: rgba(255, 255, 255, 0.98); --guide-border: rgba(102, 126, 234, 0.2); --guide-text-title: #2d3748; --guide-text-body: #4a5568; --guide-accent: #667eea; --primary-gradient-guide: linear-gradient(135deg, #667eea 0%, #764ba2 100%); --success-gradient-guide: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%); --radius-md-guide: 12px; --radius-lg-guide: 16px; --shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07), 0 8px 10px -6px rgba(26, 32, 44, 0.05); }
|
| 841 |
@keyframes float { 0%, 100% { transform: translateY(0px); } 50% { transform: translateY(-10px); } }
|
| 842 |
@keyframes slideInUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
|
|
|
|
| 873 |
"""
|
| 874 |
|
| 875 |
def apply_example(idx: str):
|
| 876 |
+
# Standard Gr.Examples handler (returns raw values)
|
| 877 |
+
# The new Examples component passes the values directly, no need for complex lookup usually
|
| 878 |
+
# But since we use a custom list, we might just pass the list values
|
| 879 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 880 |
|
| 881 |
+
# Since we are using standard gr.Examples, we don't need the complex lookup function
|
| 882 |
+
# Gradio handles mapping automatically if set up right.
|
| 883 |
|
| 884 |
####################################################################################################
|
| 885 |
### PART 20: Gradio UI Layout & Launch
|
| 886 |
####################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 887 |
|
| 888 |
with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
|
| 889 |
|
| 890 |
# --- JS QUOTA HANDLER ---
|
|
|
|
|
|
|
|
|
|
| 891 |
js_quota_handler = """
|
| 892 |
<script>
|
| 893 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
| 1009 |
|
| 1010 |
gr.HTML(js_quota_handler)
|
| 1011 |
|
| 1012 |
+
# Standard HTML Header
|
| 1013 |
gr.HTML(
|
| 1014 |
"""
|
| 1015 |
+
<div class="title-container">
|
| 1016 |
+
<h1 class="title-text">ساخت ویدیو با هوش مصنوعی</h1>
|
| 1017 |
+
<p class="subtitle-text">با پشتیبانی از صدا و دو تصویر</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
</div>
|
| 1019 |
"""
|
| 1020 |
)
|
| 1021 |
|
| 1022 |
with gr.Column(elem_id="col-container"):
|
| 1023 |
+
with gr.Row():
|
| 1024 |
+
# Standard Radio Button instead of Custom one
|
| 1025 |
+
mode_radio = gr.Radio(
|
| 1026 |
choices=["تبدیل تصویر به ویدیو", "تکمیل فریمهای میانی"],
|
| 1027 |
value="تبدیل تصویر به ویدیو",
|
| 1028 |
+
label="حالت اجرا",
|
| 1029 |
+
interactive=True
|
| 1030 |
)
|
| 1031 |
+
|
| 1032 |
with gr.Row():
|
| 1033 |
with gr.Column(elem_id="step-column"):
|
| 1034 |
|
| 1035 |
with gr.Row():
|
|
|
|
| 1036 |
first_frame = gr.Image(
|
| 1037 |
label="تصویر اول (اختیاری)",
|
| 1038 |
type="filepath",
|
|
|
|
| 1046 |
visible=False,
|
| 1047 |
)
|
| 1048 |
|
| 1049 |
+
# input_video is defined but hidden (backend legacy)
|
| 1050 |
input_video = gr.Video(
|
| 1051 |
label="Motion Reference Video",
|
| 1052 |
height=256,
|
| 1053 |
visible=False,
|
| 1054 |
)
|
| 1055 |
|
| 1056 |
+
# Standard Textbox instead of PromptBox
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1057 |
prompt = gr.Textbox(
|
| 1058 |
+
label="متن دستور (Prompt)",
|
| 1059 |
value="این تصویر را با حرکت سینمایی و انیمیشن روان زنده کن",
|
| 1060 |
lines=3,
|
|
|
|
| 1061 |
placeholder="حرکت و انیمیشن مورد نظر خود را توصیف کنید...",
|
| 1062 |
+
)
|
| 1063 |
+
|
| 1064 |
+
# Standard Audio Input instead of Custom Uploader
|
| 1065 |
+
audio_input = gr.Audio(
|
| 1066 |
+
label="فایل صوتی (اختیاری)",
|
| 1067 |
+
type="filepath",
|
| 1068 |
)
|
| 1069 |
|
| 1070 |
enhance_prompt = gr.Checkbox(
|
| 1071 |
+
label="بهبود خودکار متن (Enhance Prompt)",
|
| 1072 |
value=True,
|
| 1073 |
visible=False
|
| 1074 |
)
|
| 1075 |
|
| 1076 |
+
with gr.Accordion("تنظیمات پیشرفته", open=False):
|
| 1077 |
seed = gr.Slider(
|
| 1078 |
label="سید (Seed)",
|
| 1079 |
minimum=0,
|
|
|
|
| 1088 |
with gr.Column(elem_id="step-column"):
|
| 1089 |
output_video = gr.Video(label="ویدیوی ساخته شده", autoplay=True, height=512)
|
| 1090 |
|
| 1091 |
+
with gr.Row():
|
| 1092 |
+
# Standard Dropdowns instead of Custom
|
| 1093 |
+
duration_dropdown = gr.Dropdown(
|
| 1094 |
choices=["3s", "5s", "10s"],
|
| 1095 |
value="5s",
|
| 1096 |
+
label="مدت زمان",
|
| 1097 |
+
interactive=True
|
| 1098 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1099 |
|
| 1100 |
+
resolution_dropdown = gr.Dropdown(
|
| 1101 |
+
choices=["16:9", "1:1", "9:16"],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1102 |
value="16:9",
|
| 1103 |
+
label="ابعاد تصویر",
|
| 1104 |
+
interactive=True
|
| 1105 |
)
|
| 1106 |
|
| 1107 |
+
camera_dropdown = gr.Dropdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1108 |
choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES],
|
| 1109 |
value="No LoRA",
|
| 1110 |
+
label="افکت دوربین (LoRA)",
|
| 1111 |
+
interactive=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1112 |
)
|
| 1113 |
|
| 1114 |
+
# Hidden state holders
|
| 1115 |
+
width = gr.Number(label="Width", value=DEFAULT_1_STAGE_WIDTH, visible=False)
|
| 1116 |
+
height = gr.Number(label="Height", value=DEFAULT_1_STAGE_HEIGHT, visible=False)
|
| 1117 |
+
duration_val = gr.Number(value=5.0, visible=False)
|
| 1118 |
+
|
| 1119 |
# IMPORTANT: Added elem_id="generate-btn" for JS control
|
| 1120 |
generate_btn = gr.Button("🤩 ساخت ویدیو", variant="primary", elem_classes="button-gradient", elem_id="generate-btn")
|
| 1121 |
|
| 1122 |
|
| 1123 |
+
# Logic Linking
|
| 1124 |
+
|
| 1125 |
+
def update_resolution_vars(choice):
|
| 1126 |
+
w, h = apply_resolution(choice)
|
| 1127 |
+
return w, h
|
| 1128 |
+
|
| 1129 |
+
resolution_dropdown.change(
|
| 1130 |
+
fn=update_resolution_vars,
|
| 1131 |
+
inputs=resolution_dropdown,
|
| 1132 |
+
outputs=[width, height]
|
|
|
|
|
|
|
| 1133 |
)
|
| 1134 |
|
| 1135 |
+
def update_duration_var(choice):
|
| 1136 |
+
return apply_duration(choice)
|
| 1137 |
|
| 1138 |
+
duration_dropdown.change(
|
| 1139 |
+
fn=update_duration_var,
|
| 1140 |
+
inputs=duration_dropdown,
|
| 1141 |
+
outputs=[duration_val]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1142 |
)
|
| 1143 |
|
| 1144 |
+
mode_radio.change(
|
| 1145 |
+
fn=on_mode_change,
|
| 1146 |
+
inputs=mode_radio,
|
| 1147 |
+
outputs=[input_video, end_frame],
|
| 1148 |
+
)
|
| 1149 |
|
| 1150 |
generate_btn.click(
|
| 1151 |
fn=generate_video,
|
|
|
|
| 1153 |
first_frame,
|
| 1154 |
end_frame,
|
| 1155 |
prompt,
|
| 1156 |
+
duration_val,
|
| 1157 |
input_video,
|
| 1158 |
+
mode_radio,
|
| 1159 |
enhance_prompt,
|
| 1160 |
seed,
|
| 1161 |
randomize_seed,
|
| 1162 |
height,
|
| 1163 |
width,
|
| 1164 |
+
camera_dropdown,
|
| 1165 |
audio_input
|
| 1166 |
],
|
| 1167 |
outputs=[output_video]
|
| 1168 |
)
|
| 1169 |
|
| 1170 |
+
# Standard Examples Component
|
| 1171 |
examples_list = [
|
| 1172 |
[
|
| 1173 |
"examples/supergirl-2.png",
|
| 1174 |
+
None, # End frame
|
| 1175 |
+
"A fuzzy puppet superhero character resembling a female puppet with blonde hair and a blue superhero suit sleeping in bed and just waking up...",
|
| 1176 |
"Static",
|
| 1177 |
"16:9",
|
| 1178 |
"تبدیل تصویر به ویدیو",
|
|
|
|
| 1179 |
"examples/supergirl.m4a",
|
|
|
|
| 1180 |
],
|
| 1181 |
[
|
| 1182 |
"examples/frame3.png",
|
| 1183 |
+
"examples/frame4.png", # End frame
|
| 1184 |
+
"a woman in a white dress standing in a supermarket, looking at a stack of pomegranates...",
|
| 1185 |
"Zoom In",
|
| 1186 |
"16:9",
|
| 1187 |
"تکمیل فریمهای میانی",
|
| 1188 |
None,
|
|
|
|
|
|
|
| 1189 |
],
|
| 1190 |
[
|
| 1191 |
"examples/supergirl.png",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1192 |
None,
|
| 1193 |
+
"A fuzzy puppet superhero character resembling a female puppet with blonde hair...",
|
|
|
|
|
|
|
|
|
|
| 1194 |
"No LoRA",
|
| 1195 |
"16:9",
|
| 1196 |
"تبدیل تصویر به ویدیو",
|
| 1197 |
None,
|
|
|
|
|
|
|
| 1198 |
],
|
| 1199 |
[
|
| 1200 |
"examples/wednesday.png",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1201 |
None,
|
| 1202 |
+
"A cinematic dolly out of Wednesday Addams frozen mid-dance...",
|
| 1203 |
+
"Zoom Out",
|
| 1204 |
+
"16:9",
|
|
|
|
|
|
|
|
|
|
| 1205 |
"تبدیل تصویر به ویدیو",
|
| 1206 |
None,
|
| 1207 |
+
]
|
|
|
|
|
|
|
| 1208 |
]
|
| 1209 |
|
| 1210 |
+
# Map examples to inputs
|
| 1211 |
+
# Inputs order in list: [first_frame, end_frame, prompt, camera, res, mode, audio]
|
| 1212 |
+
# Inputs order in function: [first_frame, end_frame, prompt, duration, input_video, mode, enhance, seed, rand, h, w, cam, audio]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1213 |
|
| 1214 |
+
# To simplify, we just use a clickable gallery or standard Examples that populates fields
|
| 1215 |
+
gr.Examples(
|
| 1216 |
+
examples=examples_list,
|
| 1217 |
+
inputs=[first_frame, end_frame, prompt, camera_dropdown, resolution_dropdown, mode_radio, audio_input],
|
| 1218 |
+
label="نمونهها"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1219 |
)
|
| 1220 |
|
| 1221 |
if __name__ == "__main__":
|
| 1222 |
+
demo.launch(ssr_mode=False, css=css, allowed_paths=["./examples"])
|