Spaces:
Paused
Paused
P3.4: Video + Stems studios to DoD with hand-offs
Browse files- app.js +6 -5
- avatar.js +1 -1
- index.html +2 -2
- master.js +1 -1
- server/infer.py +11 -0
- style.css +6 -0
- video.js +158 -0
- workspace.js +2 -2
app.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
-
import './real.js?v=
|
| 4 |
-
import './avatar.js?v=
|
| 5 |
-
import './master.js?v=
|
| 6 |
-
import './
|
| 7 |
-
import
|
|
|
|
| 8 |
import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
|
| 9 |
import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
|
| 10 |
import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
|
|
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
+
import './real.js?v=76';
|
| 4 |
+
import './avatar.js?v=76';
|
| 5 |
+
import './master.js?v=76';
|
| 6 |
+
import './video.js?v=76';
|
| 7 |
+
import './workspace.js?v=76';
|
| 8 |
+
import { icon } from './icons.js?v=76';
|
| 9 |
import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
|
| 10 |
import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
|
| 11 |
import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
|
avatar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
|
| 2 |
// avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
|
| 3 |
import { STUDIOS, onStop } from './widgets.js?v=50';
|
| 4 |
-
import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=
|
| 5 |
|
| 6 |
const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
|
| 7 |
const slug = (n) => (n || 'avatar').toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'avatar';
|
|
|
|
| 1 |
// Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
|
| 2 |
// avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
|
| 3 |
import { STUDIOS, onStop } from './widgets.js?v=50';
|
| 4 |
+
import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=76';
|
| 5 |
|
| 6 |
const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
|
| 7 |
const slug = (n) => (n || 'avatar').toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'avatar';
|
index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
<title>STUDIUS · DAS Studio — Einswarm</title>
|
| 9 |
<link rel="icon" href="assets/einswarm-mascot.webp">
|
| 10 |
<link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
-
<link rel="stylesheet" href="style.css?v=
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
@@ -49,6 +49,6 @@
|
|
| 49 |
|
| 50 |
<a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
|
| 51 |
<noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
|
| 52 |
-
<script type="module" src="app.js?v=
|
| 53 |
</body>
|
| 54 |
</html>
|
|
|
|
| 8 |
<title>STUDIUS · DAS Studio — Einswarm</title>
|
| 9 |
<link rel="icon" href="assets/einswarm-mascot.webp">
|
| 10 |
<link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
+
<link rel="stylesheet" href="style.css?v=76">
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
|
|
| 49 |
|
| 50 |
<a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
|
| 51 |
<noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
|
| 52 |
+
<script type="module" src="app.js?v=76"></script>
|
| 53 |
</body>
|
| 54 |
</html>
|
master.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
|
| 2 |
// (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
|
| 3 |
import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
|
| 4 |
-
import { result, MODULES, esc, setS, keep } from './real.js?v=
|
| 5 |
|
| 6 |
/* ---------- BS.1770 loudness ---------- */
|
| 7 |
function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
|
|
| 1 |
// Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
|
| 2 |
// (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
|
| 3 |
import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
|
| 4 |
+
import { result, MODULES, esc, setS, keep } from './real.js?v=76';
|
| 5 |
|
| 6 |
/* ---------- BS.1770 loudness ---------- */
|
| 7 |
function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
server/infer.py
CHANGED
|
@@ -15,8 +15,10 @@ ALLOW = { # space -> allowed endpoints (Module API backends)
|
|
| 15 |
"ACE-Step/ACE-Step": {"/__call__"},
|
| 16 |
"declare-lab/TangoFlux": {"/predict"},
|
| 17 |
"abidlabs/music-separation": {"/inference"},
|
|
|
|
| 18 |
"Qwen/Qwen3-TTS": {"/generate_voice_design", "/generate_voice_clone"},
|
| 19 |
}
|
|
|
|
| 20 |
TMP: dict[str, tuple[str, float]] = {}
|
| 21 |
TMPDIR = Path(tempfile.gettempdir()) / "studius-tmp"; TMPDIR.mkdir(exist_ok=True)
|
| 22 |
CLIENTS: dict[tuple, tuple[Client, float]] = {}
|
|
@@ -67,6 +69,15 @@ def make_router(session):
|
|
| 67 |
if not p: raise HTTPException(400, "tmp file expired")
|
| 68 |
args[k] = handle_file(p)
|
| 69 |
timeout = min(float(form.get("timeout") or 240), 600); tok = s["token"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
q: asyncio.Queue = asyncio.Queue(); loop = asyncio.get_running_loop()
|
| 71 |
def worker():
|
| 72 |
emit = lambda e: loop.call_soon_threadsafe(q.put_nowait, e)
|
|
|
|
| 15 |
"ACE-Step/ACE-Step": {"/__call__"},
|
| 16 |
"declare-lab/TangoFlux": {"/predict"},
|
| 17 |
"abidlabs/music-separation": {"/inference"},
|
| 18 |
+
"Lightricks/ltx-video-distilled": {"/text_to_video"},
|
| 19 |
"Qwen/Qwen3-TTS": {"/generate_voice_design", "/generate_voice_clone"},
|
| 20 |
}
|
| 21 |
+
PATH_ARGS = {("Lightricks/ltx-video-distilled", "/text_to_video"): {"input_image_filepath", "input_video_filepath"}} # str-typed filepath args: upload to the Space, pass its server path
|
| 22 |
TMP: dict[str, tuple[str, float]] = {}
|
| 23 |
TMPDIR = Path(tempfile.gettempdir()) / "studius-tmp"; TMPDIR.mkdir(exist_ok=True)
|
| 24 |
CLIENTS: dict[tuple, tuple[Client, float]] = {}
|
|
|
|
| 69 |
if not p: raise HTTPException(400, "tmp file expired")
|
| 70 |
args[k] = handle_file(p)
|
| 71 |
timeout = min(float(form.get("timeout") or 240), 600); tok = s["token"]
|
| 72 |
+
for k in PATH_ARGS.get((space, ep), ()):
|
| 73 |
+
v = args.get(k)
|
| 74 |
+
if isinstance(v, dict) and v.get("path"): # handle_file() result -> upload to the Space's /gradio_api/upload
|
| 75 |
+
c = client(space, tok); base = c.src.rstrip("/")
|
| 76 |
+
import httpx as _hx
|
| 77 |
+
with open(v["path"], "rb") as fh:
|
| 78 |
+
r = _hx.post(f"{base}/gradio_api/upload", files={"files": (Path(v["path"]).name, fh)}, headers={"Authorization": f"Bearer {tok}"}, timeout=120)
|
| 79 |
+
if r.status_code != 200: raise HTTPException(502, f"upload to space failed: HTTP {r.status_code}")
|
| 80 |
+
args[k] = r.json()[0]
|
| 81 |
q: asyncio.Queue = asyncio.Queue(); loop = asyncio.get_running_loop()
|
| 82 |
def worker():
|
| 83 |
emit = lambda e: loop.call_soon_threadsafe(q.put_nowait, e)
|
style.css
CHANGED
|
@@ -232,3 +232,9 @@ body:not(.live) #beebtn{display:none}
|
|
| 232 |
@keyframes pulse{50%{opacity:.3}}
|
| 233 |
.hbtn.q{cursor:default;color:#9fe39f;border-color:rgba(159,227,159,.4)}.hbtn.q.mid{color:#f2c94c;border-color:#f2c94c}.hbtn.q.low{color:#ff8a7a;border-color:#ff8a7a}
|
| 234 |
.qnote{margin:6px 0;padding:6px 8px;border-radius:4px;font-size:11px;line-height:1.4;background:rgba(242,201,76,.1);border:1px solid rgba(242,201,76,.4)}.qnote.err{background:rgba(255,90,70,.1);border-color:rgba(255,120,100,.5)}.qnote a{color:var(--gold)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
@keyframes pulse{50%{opacity:.3}}
|
| 233 |
.hbtn.q{cursor:default;color:#9fe39f;border-color:rgba(159,227,159,.4)}.hbtn.q.mid{color:#f2c94c;border-color:#f2c94c}.hbtn.q.low{color:#ff8a7a;border-color:#ff8a7a}
|
| 234 |
.qnote{margin:6px 0;padding:6px 8px;border-radius:4px;font-size:11px;line-height:1.4;background:rgba(242,201,76,.1);border:1px solid rgba(242,201,76,.4)}.qnote.err{background:rgba(255,90,70,.1);border-color:rgba(255,120,100,.5)}.qnote a{color:var(--gold)}
|
| 235 |
+
.vg{flex-wrap:wrap;gap:8px;align-items:center}.vg label{display:inline-flex;gap:4px;align-items:center}.vg select,#pop .ctl select,#pop .ctl input.tt{background:rgba(0,0,0,.55);border:1px solid rgba(242,201,76,.25);color:var(--txt);font:inherit;padding:4px 6px;border-radius:4px}
|
| 236 |
+
#pop .ctl .tt{flex:1;min-width:0}#pop .vw video,#pop .out video{width:100%;border-radius:4px;margin-top:6px;background:#000}
|
| 237 |
+
.stems{display:flex;flex-direction:column;gap:4px;margin:8px 0}.stem{display:grid;grid-template-columns:90px 1fr 26px 26px;gap:6px;align-items:center}.stem.off{opacity:.45}.stem .sv{grid-column:1/-1}
|
| 238 |
+
.stem .ib[aria-pressed=true]{background:var(--gold);color:#000}
|
| 239 |
+
@media (max-width:1600px){#bkchip{max-width:150px}#bkchip .s{overflow:hidden;text-overflow:ellipsis;max-width:105px;display:inline-block;vertical-align:middle}}
|
| 240 |
+
@media (max-width:1440px){#bkchip .s{display:none}#bkchip{max-width:48px;padding:0 8px}.hbtn.q .s{font-size:10px}}
|
video.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// STUDIUS P3.4: Video Gen (LTX-Video, text→video + image→video), Video Edit (trim, soundtrack, title, fades → MP4/WebM export)
|
| 2 |
+
// and Stems (Demucs split → synced mixer with gain/mute/solo → WAV mixdown). All results go on the asset bus (save / send).
|
| 3 |
+
import { run, result, MODULES, esc, hf, stTxt, url, badge, timer, setS, S, keep } from './real.js?v=76';
|
| 4 |
+
import { toWav } from './master.js?v=76';
|
| 5 |
+
import { onStop } from './widgets.js?v=50';
|
| 6 |
+
|
| 7 |
+
export const LTX = 'Lightricks/ltx-video-distilled';
|
| 8 |
+
const toBlob = async (u) => (await fetch(u, { credentials: 'include' })).blob();
|
| 9 |
+
const fmt = (s) => String(Math.floor(s / 60)).padStart(2, '0') + ':' + (s % 60).toFixed(1).padStart(4, '0');
|
| 10 |
+
|
| 11 |
+
/* ---------- VIDEO GEN ---------- */
|
| 12 |
+
export async function genVideo({ prompt, image, seconds = 2, size = '704x512' }, on = {}) {
|
| 13 |
+
const [w, h] = size.split('x').map(Number);
|
| 14 |
+
const d = await run(LTX, '/text_to_video', { prompt, negative_prompt: 'worst quality, inconsistent motion, blurry, jittery, distorted', input_image_filepath: image || null, input_video_filepath: null,
|
| 15 |
+
height_ui: h, width_ui: w, mode: image ? 'image-to-video' : 'text-to-video', duration_ui: Math.max(1, Math.min(6, +seconds || 2)), ui_frames_to_use: 9, seed_ui: 42, randomize_seed: true, ui_guidance_scale: 1, improve_texture_flag: true },
|
| 16 |
+
{ el: on.el, timeout: 240000, onStatus: on.status });
|
| 17 |
+
const v = d[0]?.video ?? d[0]; return { kind: 'video', mime: 'video/mp4', url: url(v), name: `ltx-${d[1] ?? Date.now()}.mp4`, studio: 'videogen', prompt, seed: d[1] };
|
| 18 |
+
}
|
| 19 |
+
{ const s = S('videogen'); s.real = 'API'; s.accepts = ['image'];
|
| 20 |
+
s.build = (el) => {
|
| 21 |
+
el.innerHTML = `<div class="row" style="margin:0 0 6px"><span class="badge real">REAL</span><span class="stat">Text → Video oder Bild → Video</span></div>
|
| 22 |
+
<textarea rows="2" class="pr" aria-label="Video-Prompt">a golden honey bee flying over glowing hexagon crystals, cinematic light, slow camera push-in</textarea>
|
| 23 |
+
<div class="row vg"><label>Dauer <select class="dur" aria-label="Dauer"><option value="2">2 s</option><option value="3">3 s</option><option value="5">5 s</option></select></label>
|
| 24 |
+
<label>Format <select class="sz" aria-label="Format"><option value="704x512">Quer 704×512</option><option value="512x704">Hoch 512×704</option><option value="512x512">Quadrat 512</option></select></label></div>
|
| 25 |
+
<div class="row vg"><label class="btn alt">🖼 Startbild<input type="file" accept="image/*" hidden class="img"></label><span class="imgn mut">kein Startbild → Text-zu-Video</span><button class="ib clr" hidden aria-label="Startbild entfernen">✕</button></div>
|
| 26 |
+
<div class="row"><button class="btn go">🎬 Video erzeugen</button><a class="btn alt dl" hidden>⬇ MP4</a></div><div class="out"></div>
|
| 27 |
+
<div class="credit">powered by ${hf(LTX)} (LTX-Video distilled) · Ergebnis → Video Edit für Schnitt, Musik & Titel</div>`;
|
| 28 |
+
keep(el); let img = null; const q = (x) => el.querySelector(x);
|
| 29 |
+
const setImg = (f) => { img = f; GEN.img = f; q('.imgn').textContent = f ? '🖼 ' + (f.name || 'Startbild') + ' → Bild-zu-Video' : 'kein Startbild → Text-zu-Video'; q('.clr').hidden = !f; };
|
| 30 |
+
q('.img').onchange = () => setImg(q('.img').files[0] || null); q('.clr').onclick = () => setImg(null);
|
| 31 |
+
el.__setImage = setImg; if (GEN.img) setImg(GEN.img);
|
| 32 |
+
q('.go').onclick = async () => { const go = q('.go'); go.disabled = true; const tm = timer(el, '.stat'); setS(el, 'Starte…');
|
| 33 |
+
try { const a = await genVideo({ prompt: q('.pr').value.trim(), image: img, seconds: q('.dur').value, size: q('.sz').value }, { el, status: (m) => setS(el, stTxt(m)) });
|
| 34 |
+
q('.out').innerHTML = `<video controls loop playsinline src="${esc(a.url)}"></video>`; const dl = q('.dl'); dl.href = a.url; dl.download = a.name; dl.hidden = false;
|
| 35 |
+
window.__videoGen = { url: a.url, seed: a.seed, mode: img ? 'i2v' : 't2v' }; result(q('.out'), a); setS(el, `✔ ${img ? 'Bild' : 'Text'}-zu-Video · Seed ${a.seed}`); badge(el, 'REAL');
|
| 36 |
+
} catch (e) { if (!el.isConnected) return; setS(el, '⚠ ' + e.message, true); window.__videoGen = { err: e.message }; }
|
| 37 |
+
finally { clearInterval(tm); go.disabled = false; } };
|
| 38 |
+
};
|
| 39 |
+
s.accept = async (el, a) => { const b = a.blob || await toBlob(a.url); el.__setImage?.(new File([b], a.name || 'start.webp', { type: b.type || 'image/webp' })); return true; };
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* ---------- VIDEO EDIT: trim, soundtrack, title, fades → export ---------- */
|
| 43 |
+
const recMime = () => ['video/mp4;codecs=avc1.42E01E,mp4a.40.2', 'video/mp4', 'video/webm;codecs=vp9,opus', 'video/webm;codecs=vp8,opus', 'video/webm'].find(m => window.MediaRecorder?.isTypeSupported?.(m)) || 'video/webm';
|
| 44 |
+
export async function renderEdit({ video, audio, a = 0, b = null, title = '', pos = 'bottom', fade = 0.5, music = 0.8, orig = 0.3 }, onP = () => {}) {
|
| 45 |
+
const v = document.createElement('video'); v.src = video; v.crossOrigin = 'anonymous'; v.playsInline = true; v.preload = 'auto';
|
| 46 |
+
await new Promise((ok, no) => { v.onloadedmetadata = ok; v.onerror = () => no(new Error('Video nicht ladbar')); });
|
| 47 |
+
const end = Math.min(b ?? v.duration, v.duration), start = Math.max(0, Math.min(a, end - 0.2)), dur = end - start;
|
| 48 |
+
const W = v.videoWidth || 704, H = v.videoHeight || 512, c = document.createElement('canvas'); c.width = W; c.height = H; const x = c.getContext('2d');
|
| 49 |
+
const ac = new AudioContext(), dst = ac.createMediaStreamDestination();
|
| 50 |
+
const og = ac.createGain(); og.gain.value = orig; try { ac.createMediaElementSource(v).connect(og).connect(dst); } catch (e) {}
|
| 51 |
+
let ab = null; if (audio) { const buf = await ac.decodeAudioData(await (await toBlob(audio)).arrayBuffer()); ab = ac.createBufferSource(); ab.buffer = buf; const mg = ac.createGain(); ab.connect(mg).connect(dst);
|
| 52 |
+
mg.gain.setValueAtTime(0, ac.currentTime); mg.gain.linearRampToValueAtTime(music, ac.currentTime + Math.max(.05, fade)); mg.gain.setValueAtTime(music, ac.currentTime + Math.max(.06, dur - fade)); mg.gain.linearRampToValueAtTime(0, ac.currentTime + dur); }
|
| 53 |
+
const stream = new MediaStream([...c.captureStream(30).getVideoTracks(), ...dst.stream.getAudioTracks()]);
|
| 54 |
+
const mime = recMime(), rec = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 4e6 }), parts = []; rec.ondataavailable = (e) => e.data.size && parts.push(e.data);
|
| 55 |
+
v.currentTime = start; await new Promise(ok => v.onseeked = ok); v.muted = false; v.volume = 1;
|
| 56 |
+
const draw = () => { const t = v.currentTime - start; x.drawImage(v, 0, 0, W, H);
|
| 57 |
+
const al = Math.min(1, t / Math.max(.01, fade), (dur - t) / Math.max(.01, fade)); if (fade > 0 && al < 1) { x.fillStyle = `rgba(0,0,0,${1 - Math.max(0, al)})`; x.fillRect(0, 0, W, H); }
|
| 58 |
+
if (title) { const fs = Math.round(H / 12); x.font = `700 ${fs}px Outfit, sans-serif`; x.textAlign = 'center'; const y = pos === 'top' ? fs * 1.6 : pos === 'center' ? H / 2 : H - fs * 1.1;
|
| 59 |
+
x.lineWidth = fs / 6; x.strokeStyle = 'rgba(0,0,0,.75)'; x.strokeText(title, W / 2, y); x.fillStyle = '#f2c94c'; x.fillText(title, W / 2, y); }
|
| 60 |
+
onP(Math.min(1, t / dur)); };
|
| 61 |
+
const done = new Promise(ok => rec.onstop = ok); rec.start(250); ab?.start(); await v.play();
|
| 62 |
+
await new Promise(ok => { const tick = () => { draw(); if (v.currentTime >= end - 0.03 || v.ended) return ok(); requestAnimationFrame(tick); }; tick(); });
|
| 63 |
+
v.pause(); ab?.stop(); rec.stop(); await done; ac.close();
|
| 64 |
+
const type = (rec.mimeType || mime).split(';')[0], blob = new Blob(parts, { type }); return { blob, type, codec: rec.mimeType || mime, ext: type.includes('mp4') ? 'mp4' : 'webm', dur, w: W, h: H };
|
| 65 |
+
}
|
| 66 |
+
const EDIT = { v: null, vn: '', a: null, an: '' }, GEN = { img: null }, STM = { src: null, name: '' }; // survive studio re-open (hand-offs)
|
| 67 |
+
{ const s = S('videoedit'); s.real = 'LOKAL'; s.accepts = ['video', 'audio', 'image'];
|
| 68 |
+
s.build = (el) => {
|
| 69 |
+
el.innerHTML = `<div class="row" style="margin:0 0 6px"><span class="badge real">LOKAL</span><span class="stat">Video laden – oder aus Video Gen / Workspace senden</span></div>
|
| 70 |
+
<div class="row"><label class="btn alt">🎬 Video<input type="file" accept="video/*" hidden class="vf"></label><label class="btn alt">🎵 Musik<input type="file" accept="audio/*" hidden class="af"></label><span class="an mut">keine Musik</span></div>
|
| 71 |
+
<div class="vw"><p class="mut">Noch kein Video.</p></div>
|
| 72 |
+
<div class="ctl" hidden><div class="row">In<input type="range" class="ti" min="0" max="1000" value="0" aria-label="Trim In">Out<input type="range" class="to" min="0" max="1000" value="1000" aria-label="Trim Out"></div>
|
| 73 |
+
<div class="row"><input class="tt" aria-label="Titel" placeholder="Titel-Overlay (optional)"><select class="tp" aria-label="Titelposition"><option value="bottom">unten</option><option value="center">Mitte</option><option value="top">oben</option></select></div>
|
| 74 |
+
<div class="row">Musik<input type="range" class="mv" min="0" max="100" value="80" aria-label="Musik-Lautstärke">Original<input type="range" class="ov" min="0" max="100" value="30" aria-label="Original-Lautstärke">Fade<select class="fd" aria-label="Fade"><option value="0">aus</option><option value="0.5" selected>0,5 s</option><option value="1">1 s</option></select></div>
|
| 75 |
+
<div class="row"><button class="btn alt pp">▶ Vorschau</button><button class="btn go">⬇ Rendern & exportieren</button><span class="tc code">00:00.0</span></div></div>
|
| 76 |
+
<div class="out"></div><div class="credit">Schnitt, Musik, Titel & Fades im Browser (Canvas + WebAudio → MediaRecorder, ${esc(recMime().split(';')[0])})</div>`;
|
| 77 |
+
keep(el); const q = (x) => el.querySelector(x); let vu = null, au = null, vname = 'clip';
|
| 78 |
+
const setVideo = (u, name) => { vu = u; EDIT.v = u; EDIT.vn = name; vname = (name || 'clip').replace(/\.[^.]+$/, ''); q('.vw').innerHTML = `<video playsinline src="${esc(u)}" crossorigin="anonymous"></video>`; q('.ctl').hidden = false;
|
| 79 |
+
const v = q('video'); v.onloadedmetadata = () => { sync(); window.__video = { dur: v.duration, w: v.videoWidth, h: v.videoHeight }; setS(el, `${name || 'Video'} · ${v.videoWidth}×${v.videoHeight} · ${v.duration.toFixed(1)} s`); };
|
| 80 |
+
v.ontimeupdate = () => { const [a, b] = T(); q('.tc').textContent = fmt(v.currentTime); if (v.currentTime >= b) { v.pause(); q('.pp').textContent = '▶ Vorschau'; } }; };
|
| 81 |
+
const setAudio = (u, name) => { au = u; EDIT.a = u; EDIT.an = name; q('.an').textContent = '🎵 ' + (name || 'Musik'); };
|
| 82 |
+
const T = () => { const d = q('video')?.duration || 0; return [q('.ti').value / 1000 * d, q('.to').value / 1000 * d]; };
|
| 83 |
+
const sync = () => { if (+q('.ti').value > +q('.to').value - 20) q('.ti').value = +q('.to').value - 20; const v = q('video'); if (!v) return; const [a, b] = T(); v.currentTime = a; setS(el, `Schnitt ${fmt(a)} – ${fmt(b)} (${(b - a).toFixed(1)} s)`); };
|
| 84 |
+
q('.ti').oninput = sync; q('.to').oninput = sync;
|
| 85 |
+
q('.vf').onchange = () => { const f = q('.vf').files[0]; if (!f) return; setVideo(URL.createObjectURL(f), f.name); };
|
| 86 |
+
q('.af').onchange = () => { const f = q('.af').files[0]; if (!f) return; setAudio(URL.createObjectURL(f), f.name); };
|
| 87 |
+
q('.pp').onclick = () => { const v = q('video'); if (!v) return; if (v.paused) { v.currentTime = T()[0]; v.play(); q('.pp').textContent = '⏸ Stop'; } else { v.pause(); q('.pp').textContent = '▶ Vorschau'; } };
|
| 88 |
+
q('.go').onclick = async () => { if (!vu) return; const go = q('.go'); go.disabled = true; q('video')?.pause(); const [a, b] = T();
|
| 89 |
+
try { const r = await renderEdit({ video: vu, audio: au, a, b, title: q('.tt').value.trim(), pos: q('.tp').value, fade: +q('.fd').value, music: q('.mv').value / 100, orig: q('.ov').value / 100 }, p => setS(el, `Rendere… ${Math.round(p * 100)} %`));
|
| 90 |
+
const u = URL.createObjectURL(r.blob); onStop(() => URL.revokeObjectURL(u)); const name = `${vname}-edit-${Date.now()}.${r.ext}`;
|
| 91 |
+
q('.out').innerHTML = `<video controls playsinline src="${u}"></video><div class="row"><a class="btn alt" href="${u}" download="${esc(name)}">⬇ ${r.ext.toUpperCase()} (${(r.blob.size / 1e6).toFixed(1)} MB)</a></div>`;
|
| 92 |
+
window.__videoEdit = { size: r.blob.size, type: r.type, codec: r.codec, dur: r.dur, music: !!au, title: q('.tt').value }; result(q('.out'), { kind: 'video', mime: r.type, blob: r.blob, url: u, name, studio: 'videoedit', prompt: q('.tt').value });
|
| 93 |
+
setS(el, `✔ Export ${r.ext.toUpperCase()} · ${r.dur.toFixed(1)} s${au ? ' · mit Musik' : ''}${q('.tt').value ? ' · mit Titel' : ''}`); badge(el, 'LOKAL');
|
| 94 |
+
} catch (e) { setS(el, '⚠ ' + e.message, true); window.__videoEdit = { err: e.message }; } finally { go.disabled = false; } };
|
| 95 |
+
el.__setVideo = setVideo; el.__setAudio = setAudio; if (EDIT.v) setVideo(EDIT.v, EDIT.vn); if (EDIT.a) setAudio(EDIT.a, EDIT.an);
|
| 96 |
+
};
|
| 97 |
+
s.accept = async (el, a) => { const u = a.blob ? URL.createObjectURL(a.blob) : a.url; if (a.kind === 'video') el.__setVideo(u, a.name); else if (a.kind === 'audio') el.__setAudio(u, a.name);
|
| 98 |
+
else { const vg = S('videogen'); setS(el, '🖼 Bilder bitte über Video Gen (Bild → Video) animieren.'); } return true; };
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/* ---------- STEMS: Demucs split → synced mixer → mixdown ---------- */
|
| 102 |
+
const SEP = 'abidlabs/music-separation';
|
| 103 |
+
{ const s = S('stems'); s.real = 'API'; s.accepts = ['audio'];
|
| 104 |
+
s.build = (el) => {
|
| 105 |
+
el.innerHTML = `<div class="row" style="margin:0 0 6px"><span class="badge real">REAL</span><span class="stat">Song laden – oder aus Music / Workspace senden</span></div>
|
| 106 |
+
<div class="row"><label class="btn alt">🎵 Audio<input type="file" accept="audio/*" hidden class="af"></label><span class="an mut">kein Audio</span></div>
|
| 107 |
+
<div class="row"><button class="btn go" disabled>✂ Stems trennen</button></div><div class="mix"></div>
|
| 108 |
+
<div class="credit">powered by ${hf(SEP)} (Demucs) · Mixer & Mixdown lokal (WebAudio) · Mix → Mastering</div>`;
|
| 109 |
+
keep(el); const q = (x) => el.querySelector(x); let src = null, srcName = 'song';
|
| 110 |
+
const setSrc = (blob, name) => { src = blob; STM.src = blob; STM.name = name; srcName = (name || 'song').replace(/\.[^.]+$/, ''); q('.an').textContent = '🎵 ' + (name || 'Audio') + ' · ' + (blob.size / 1e6).toFixed(1) + ' MB'; q('.go').disabled = false; };
|
| 111 |
+
q('.af').onchange = () => { const f = q('.af').files[0]; if (f) setSrc(f, f.name); };
|
| 112 |
+
el.__setSrc = setSrc; if (STM.src) setSrc(STM.src, STM.name);
|
| 113 |
+
q('.go').onclick = async () => { if (!src) return; if (src.size > 25e6) return setS(el, '⚠ Datei > 25 MB', true); const go = q('.go'); go.disabled = true; const tm = timer(el, '.stat'); setS(el, 'Lade hoch…');
|
| 114 |
+
try { const d = await run(SEP, '/inference', { audio: new File([src], srcName + '.wav', { type: src.type || 'audio/wav' }) }, { el, timeout: 240000, onStatus: m => setS(el, stTxt(m)) });
|
| 115 |
+
const names = d.length === 2 ? ['Vocals', 'Instrumental'] : ['Vocals', 'Drums', 'Bass', 'Other'].slice(0, d.length); const urls = d.map(url);
|
| 116 |
+
await mixer(el, names.map((n, i) => ({ name: n, url: urls[i] })), srcName); window.__stems = urls; setS(el, `✔ ${urls.length} Stems · Mixer bereit`); badge(el, 'REAL');
|
| 117 |
+
} catch (e) { if (!el.isConnected) return; setS(el, '⚠ ' + e.message, true); window.__stems = { err: e.message }; }
|
| 118 |
+
finally { clearInterval(tm); go.disabled = false; } };
|
| 119 |
+
};
|
| 120 |
+
s.accept = async (el, a) => { const b = a.blob || await toBlob(a.url); el.__setSrc(b, a.name); return true; };
|
| 121 |
+
}
|
| 122 |
+
async function mixer(el, stems, base) {
|
| 123 |
+
const ac = new AudioContext(); onStop(() => ac.close()); const box = el.querySelector('.mix');
|
| 124 |
+
const bufs = await Promise.all(stems.map(async s => ac.decodeAudioData(await (await toBlob(s.url)).arrayBuffer())));
|
| 125 |
+
const st = stems.map((s, i) => ({ ...s, buf: bufs[i], gain: 1, mute: false, solo: false }));
|
| 126 |
+
box.innerHTML = `<div class="stems">${st.map((s, i) => `<div class="stem" data-i="${i}"><b>${esc(s.name)}</b><input type="range" min="0" max="150" value="100" class="g" aria-label="${esc(s.name)} Pegel"><button class="ib m" aria-pressed="false" aria-label="${esc(s.name)} stumm">M</button><button class="ib so" aria-pressed="false" aria-label="${esc(s.name)} solo">S</button><span class="sv"></span></div>`).join('')}</div>
|
| 127 |
+
<div class="row"><button class="btn alt pl">▶ Mix abspielen</button><button class="btn go2">⬇ Mixdown (WAV)</button><span class="tc code">00:00.0</span></div><div class="mo"></div>`;
|
| 128 |
+
st.forEach((s, i) => result(box.querySelectorAll('.stem .sv')[i], { kind: 'audio', url: s.url, name: `${base}-${s.name.toLowerCase()}.wav`, studio: 'stems', prompt: s.name }));
|
| 129 |
+
const eff = (s) => (s.mute || (st.some(x => x.solo) && !s.solo)) ? 0 : s.gain;
|
| 130 |
+
let nodes = null, t0 = 0, raf = 0;
|
| 131 |
+
const stop = () => { nodes?.forEach(n => { try { n.src.stop(); } catch (e) {} }); nodes = null; cancelAnimationFrame(raf); box.querySelector('.pl').textContent = '▶ Mix abspielen'; };
|
| 132 |
+
const play = () => { stop(); t0 = ac.currentTime; nodes = st.map(s => { const src = ac.createBufferSource(); src.buffer = s.buf; const g = ac.createGain(); g.gain.value = eff(s); src.connect(g).connect(ac.destination); src.start(); return { src, g }; });
|
| 133 |
+
nodes[0].src.onended = stop; box.querySelector('.pl').textContent = '⏹ Stop'; const tick = () => { box.querySelector('.tc').textContent = fmt(ac.currentTime - t0); raf = requestAnimationFrame(tick); }; tick(); };
|
| 134 |
+
const upd = () => { nodes?.forEach((n, i) => n.g.gain.setTargetAtTime(eff(st[i]), ac.currentTime, .02)); box.querySelectorAll('.stem').forEach((r, i) => { r.classList.toggle('off', eff(st[i]) === 0); r.querySelector('.m').setAttribute('aria-pressed', st[i].mute); r.querySelector('.so').setAttribute('aria-pressed', st[i].solo); }); window.__mix = st.map(s => ({ name: s.name, gain: eff(s) })); };
|
| 135 |
+
box.querySelector('.stems').oninput = (e) => { const r = e.target.closest('.stem'); if (r && e.target.classList.contains('g')) { st[r.dataset.i].gain = e.target.value / 100; upd(); } };
|
| 136 |
+
box.querySelector('.stems').onclick = (e) => { const r = e.target.closest('.stem'); if (!r) return; const s = st[r.dataset.i]; if (e.target.classList.contains('m')) s.mute = !s.mute; else if (e.target.classList.contains('so')) s.solo = !s.solo; else return; upd(); };
|
| 137 |
+
box.querySelector('.pl').onclick = () => nodes ? stop() : play();
|
| 138 |
+
box.querySelector('.go2').onclick = async () => { const n = Math.max(...bufs.map(b => b.length)), sr = bufs[0].sampleRate, oc = new OfflineAudioContext(2, n, sr);
|
| 139 |
+
st.forEach(s => { const src = oc.createBufferSource(); src.buffer = s.buf; const g = oc.createGain(); g.gain.value = eff(s); src.connect(g).connect(oc.destination); src.start(); });
|
| 140 |
+
const out = await oc.startRendering(); let pk = 0; for (let c = 0; c < out.numberOfChannels; c++) { const d = out.getChannelData(c); for (let i = 0; i < d.length; i++) pk = Math.max(pk, Math.abs(d[i])); }
|
| 141 |
+
if (pk > .99) for (let c = 0; c < out.numberOfChannels; c++) { const d = out.getChannelData(c); for (let i = 0; i < d.length; i++) d[i] *= .99 / pk; }
|
| 142 |
+
const blob = toWav(out), u = URL.createObjectURL(blob); onStop(() => URL.revokeObjectURL(u)); const name = `${base}-mix-${Date.now()}.wav`, tag = st.map(s => s.name + ':' + Math.round(eff(s) * 100)).join(' ');
|
| 143 |
+
const mo = box.querySelector('.mo'); mo.innerHTML = `<audio controls src="${u}"></audio><div class="row"><a class="btn alt" href="${u}" download="${esc(name)}">⬇ Mix WAV</a></div>`;
|
| 144 |
+
window.__mixdown = { size: blob.size, tag, limited: pk > .99 }; result(mo, { kind: 'audio', mime: 'audio/wav', blob, url: u, name, studio: 'stems', prompt: 'Mix ' + tag }); setS(el, '✔ Mixdown · ' + tag); };
|
| 145 |
+
upd();
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
/* ---------- Module API ---------- */
|
| 149 |
+
MODULES.video = { id: 'video', name: 'Video', backend: LTX + ' + lokaler Schnitt', inputs: [{ name: 'prompt', type: 'text' }, { name: 'image', type: 'image-url' }], outputs: [{ kind: 'video' }],
|
| 150 |
+
actions: {
|
| 151 |
+
generate: { desc: 'Erzeugt ein 2–5 s Video aus einem Prompt (optional Startbild-url eines vorherigen Bildes)', params: { prompt: 'string', seconds: 'number' },
|
| 152 |
+
run: async ({ prompt, seconds = 2, image }, on = {}) => genVideo({ prompt, seconds, image: image ? await toBlob(image) : null }, { status: on.status }) },
|
| 153 |
+
score: { desc: 'Legt Musik (audio url) unter ein Video (video url), optional mit Titel, und exportiert es', params: { video: 'string', audio: 'string', title: 'string' },
|
| 154 |
+
run: async ({ video, audio, title = '' }) => { const r = await renderEdit({ video, audio, title }); const u = URL.createObjectURL(r.blob); return { kind: 'video', mime: r.type, blob: r.blob, url: u, name: `scored-${Date.now()}.${r.ext}`, studio: 'videoedit', prompt: title, text: `Video mit Musik (${r.dur.toFixed(1)} s)` }; } } } };
|
| 155 |
+
MODULES.stems = { id: 'stems', name: 'Stems', backend: SEP, inputs: [{ name: 'source', type: 'audio-url' }], outputs: [{ kind: 'audio' }],
|
| 156 |
+
actions: { split: { desc: 'Trennt ein Audio (url) in Vocals + Instrumental; liefert das Instrumental', params: { source: 'string' },
|
| 157 |
+
run: async ({ source }, on = {}) => { const d = await run(SEP, '/inference', { audio: new File([await toBlob(source)], 'in.wav', { type: 'audio/wav' }) }, { onStatus: on.status, timeout: 240000 }); const u = d.map(url);
|
| 158 |
+
return { kind: 'audio', url: u[1] || u[0], stems: u, name: `instrumental-${Date.now()}.wav`, studio: 'stems', text: `${u.length} Stems getrennt` }; } } } };
|
workspace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
// STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
|
| 2 |
-
import { MODULES, refreshQuota } from './real.js?v=
|
| 3 |
-
import { Avatars } from './avatar.js?v=
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|
|
|
|
| 1 |
// STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
|
| 2 |
+
import { MODULES, refreshQuota } from './real.js?v=76';
|
| 3 |
+
import { Avatars } from './avatar.js?v=76';
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|