Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- app.py +23 -1
- workflow.json +27 -29
app.py
CHANGED
|
@@ -159,6 +159,28 @@ def encode_remote(prompt, references, canvas, num_frames):
|
|
| 159 |
|
| 160 |
|
| 161 |
# ------------------------------------------------------------------------------------------------------ pure helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
def read_video(path: str, limit: int | None = None) -> np.ndarray:
|
| 163 |
import av
|
| 164 |
|
|
@@ -333,7 +355,7 @@ def _generate(request, steps, seed):
|
|
| 333 |
def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, progress=None):
|
| 334 |
"""Clip + a background description -> the subject on that new background."""
|
| 335 |
progress = progress or (lambda *a, **k: None)
|
| 336 |
-
clip =
|
| 337 |
if LOAD_ERROR:
|
| 338 |
raise gr.Error(LOAD_ERROR)
|
| 339 |
if PIPE is None:
|
|
|
|
| 159 |
|
| 160 |
|
| 161 |
# ------------------------------------------------------------------------------------------------------ pure helpers
|
| 162 |
+
def _resolve_clip(clip) -> str:
|
| 163 |
+
"""A clip input into a local filepath. Accepts a path str, a FileData dict, or a (possibly private) URL -
|
| 164 |
+
the Examples dataset hands media as a {url: src} to a token-gated datasets-server file, so fetch it here with
|
| 165 |
+
the Space's token (handle_file would reach it anonymously and 401)."""
|
| 166 |
+
import tempfile as _tf
|
| 167 |
+
|
| 168 |
+
if isinstance(clip, dict):
|
| 169 |
+
clip = clip.get("path") or clip.get("url")
|
| 170 |
+
if isinstance(clip, str) and clip.startswith(("http://", "https://")):
|
| 171 |
+
import requests
|
| 172 |
+
|
| 173 |
+
tok = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 174 |
+
headers = {"Authorization": f"Bearer {tok}"} if tok else {}
|
| 175 |
+
resp = requests.get(clip, headers=headers, timeout=120)
|
| 176 |
+
resp.raise_for_status()
|
| 177 |
+
local = os.path.join(_tf.mkdtemp(), "example-clip.mp4")
|
| 178 |
+
with open(local, "wb") as handle:
|
| 179 |
+
handle.write(resp.content)
|
| 180 |
+
return local
|
| 181 |
+
return clip
|
| 182 |
+
|
| 183 |
+
|
| 184 |
def read_video(path: str, limit: int | None = None) -> np.ndarray:
|
| 185 |
import av
|
| 186 |
|
|
|
|
| 355 |
def replace_background(clip, prompt, relight, budget, steps, seed, keep_audio, progress=None):
|
| 356 |
"""Clip + a background description -> the subject on that new background."""
|
| 357 |
progress = progress or (lambda *a, **k: None)
|
| 358 |
+
clip = _resolve_clip(clip)
|
| 359 |
if LOAD_ERROR:
|
| 360 |
raise gr.Error(LOAD_ERROR)
|
| 361 |
if PIPE is None:
|
workflow.json
CHANGED
|
@@ -1,61 +1,58 @@
|
|
| 1 |
{
|
| 2 |
"schema_version": "2",
|
| 3 |
"name": "Subject on a New Background",
|
| 4 |
-
"description": "Lift a subject from a clip with the LTX-2.5 Alpha-Gen matte, then regenerate the background around it with MiniMax-H3.
|
| 5 |
"runtime": {"default": "client"},
|
| 6 |
"view": {"default": "canvas"},
|
| 7 |
"references": [
|
| 8 |
{
|
| 9 |
-
"id": "
|
| 10 |
-
"inputs": [{"id": "in", "label": "
|
| 11 |
-
"outputs": [{"id": "out", "label": "
|
| 12 |
-
"x": 40, "y": 40, "width":
|
| 13 |
-
"data": {"out": {"path": "examples/subject.mp4", "url": "/gradio_api/file=examples/subject.mp4", "orig_name": "subject.mp4", "mime_type": "video/mp4", "meta": {"_type": "gradio.FileData"}}}
|
| 14 |
-
},
|
| 15 |
-
{
|
| 16 |
-
"id": "ref_prompt", "role": "reference", "label": "New background", "asset_type": "text",
|
| 17 |
-
"inputs": [{"id": "in", "label": "Text", "type": "text"}],
|
| 18 |
-
"outputs": [{"id": "out", "label": "Text", "type": "text"}],
|
| 19 |
-
"x": 40, "y": 220, "width": 260, "height": 150,
|
| 20 |
-
"data": {"out": "a sunny tropical beach, white sand, palm trees and turquoise ocean waves behind the subject, bright warm daylight, static camera"}
|
| 21 |
},
|
| 22 |
{
|
| 23 |
"id": "ref_relight", "role": "reference", "label": "Relight strength", "asset_type": "number",
|
| 24 |
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 25 |
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 26 |
-
"x": 40, "y":
|
| 27 |
-
"data": {"out": 0}
|
| 28 |
},
|
| 29 |
{
|
| 30 |
"id": "ref_budget", "role": "reference", "label": "Quality / speed", "asset_type": "text",
|
| 31 |
"inputs": [{"id": "in", "label": "Text", "type": "text"}],
|
| 32 |
"outputs": [{"id": "out", "label": "Text", "type": "text"}],
|
| 33 |
-
"x": 40, "y":
|
| 34 |
-
"data": {"out": "Balanced · 640"}
|
| 35 |
},
|
| 36 |
{
|
| 37 |
"id": "ref_steps", "role": "reference", "label": "Steps (turbo)", "asset_type": "number",
|
| 38 |
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 39 |
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 40 |
-
"x": 40, "y":
|
| 41 |
-
"data": {"out": 8}
|
| 42 |
},
|
| 43 |
{
|
| 44 |
"id": "ref_seed", "role": "reference", "label": "Seed", "asset_type": "number",
|
| 45 |
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 46 |
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 47 |
-
"x": 40, "y":
|
| 48 |
-
"data": {"out": 7}
|
| 49 |
},
|
| 50 |
{
|
| 51 |
"id": "ref_keep", "role": "reference", "label": "Keep original audio", "asset_type": "boolean",
|
| 52 |
"inputs": [{"id": "in", "label": "Boolean", "type": "boolean"}],
|
| 53 |
"outputs": [{"id": "out", "label": "Boolean", "type": "boolean"}],
|
| 54 |
-
"x": 40, "y":
|
| 55 |
-
"data": {"out": true}
|
| 56 |
}
|
| 57 |
],
|
| 58 |
"operators": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
{
|
| 60 |
"id": "op_generate", "role": "operator", "kind": "fn", "source": "fn", "fn": "generate_video",
|
| 61 |
"label": "generate_video",
|
|
@@ -73,7 +70,7 @@
|
|
| 73 |
{"id": "out_1", "label": "alpha matte", "type": "video", "output_index": 1},
|
| 74 |
{"id": "out_2", "label": "background mask", "type": "video", "output_index": 2}
|
| 75 |
],
|
| 76 |
-
"x":
|
| 77 |
}
|
| 78 |
],
|
| 79 |
"subjects": [
|
|
@@ -81,24 +78,25 @@
|
|
| 81 |
"id": "sub_result", "role": "subject", "label": "Result", "asset_type": "video",
|
| 82 |
"inputs": [{"id": "in", "label": "Video", "type": "video"}],
|
| 83 |
"outputs": [{"id": "out", "label": "Video", "type": "video"}],
|
| 84 |
-
"x":
|
| 85 |
},
|
| 86 |
{
|
| 87 |
"id": "sub_matte", "role": "subject", "label": "Alpha matte", "asset_type": "video",
|
| 88 |
"inputs": [{"id": "in", "label": "Video", "type": "video"}],
|
| 89 |
"outputs": [{"id": "out", "label": "Video", "type": "video"}],
|
| 90 |
-
"x":
|
| 91 |
},
|
| 92 |
{
|
| 93 |
"id": "sub_mask", "role": "subject", "label": "Background mask", "asset_type": "video",
|
| 94 |
"inputs": [{"id": "in", "label": "Video", "type": "video"}],
|
| 95 |
"outputs": [{"id": "out", "label": "Video", "type": "video"}],
|
| 96 |
-
"x":
|
| 97 |
}
|
| 98 |
],
|
| 99 |
"edges": [
|
| 100 |
-
{"id": "
|
| 101 |
-
{"id": "
|
|
|
|
| 102 |
{"id": "e_relight", "from_node_id": "ref_relight", "from_port_id": "out", "to_node_id": "op_generate", "to_port_id": "in_2", "type": "number"},
|
| 103 |
{"id": "e_budget", "from_node_id": "ref_budget", "from_port_id": "out", "to_node_id": "op_generate", "to_port_id": "in_3", "type": "text"},
|
| 104 |
{"id": "e_steps", "from_node_id": "ref_steps", "from_port_id": "out", "to_node_id": "op_generate", "to_port_id": "in_4", "type": "number"},
|
|
|
|
| 1 |
{
|
| 2 |
"schema_version": "2",
|
| 3 |
"name": "Subject on a New Background",
|
| 4 |
+
"description": "Lift a subject from a clip with the LTX-2.5 Alpha-Gen matte, then regenerate the background around it with MiniMax-H3. Pick an example with the Examples node, or edit the inputs.",
|
| 5 |
"runtime": {"default": "client"},
|
| 6 |
"view": {"default": "canvas"},
|
| 7 |
"references": [
|
| 8 |
{
|
| 9 |
+
"id": "ref_row", "role": "reference", "label": "Example # (0-2)", "asset_type": "number",
|
| 10 |
+
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 11 |
+
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 12 |
+
"x": 40, "y": 40, "width": 220, "height": 110, "data": {"out": 0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
},
|
| 14 |
{
|
| 15 |
"id": "ref_relight", "role": "reference", "label": "Relight strength", "asset_type": "number",
|
| 16 |
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 17 |
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 18 |
+
"x": 40, "y": 430, "width": 220, "height": 110, "data": {"out": 0}
|
|
|
|
| 19 |
},
|
| 20 |
{
|
| 21 |
"id": "ref_budget", "role": "reference", "label": "Quality / speed", "asset_type": "text",
|
| 22 |
"inputs": [{"id": "in", "label": "Text", "type": "text"}],
|
| 23 |
"outputs": [{"id": "out", "label": "Text", "type": "text"}],
|
| 24 |
+
"x": 40, "y": 560, "width": 220, "height": 110, "data": {"out": "Balanced · 640"}
|
|
|
|
| 25 |
},
|
| 26 |
{
|
| 27 |
"id": "ref_steps", "role": "reference", "label": "Steps (turbo)", "asset_type": "number",
|
| 28 |
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 29 |
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 30 |
+
"x": 40, "y": 690, "width": 220, "height": 110, "data": {"out": 8}
|
|
|
|
| 31 |
},
|
| 32 |
{
|
| 33 |
"id": "ref_seed", "role": "reference", "label": "Seed", "asset_type": "number",
|
| 34 |
"inputs": [{"id": "in", "label": "Number", "type": "number"}],
|
| 35 |
"outputs": [{"id": "out", "label": "Number", "type": "number"}],
|
| 36 |
+
"x": 40, "y": 820, "width": 220, "height": 110, "data": {"out": 7}
|
|
|
|
| 37 |
},
|
| 38 |
{
|
| 39 |
"id": "ref_keep", "role": "reference", "label": "Keep original audio", "asset_type": "boolean",
|
| 40 |
"inputs": [{"id": "in", "label": "Boolean", "type": "boolean"}],
|
| 41 |
"outputs": [{"id": "out", "label": "Boolean", "type": "boolean"}],
|
| 42 |
+
"x": 40, "y": 950, "width": 220, "height": 100, "data": {"out": true}
|
|
|
|
| 43 |
}
|
| 44 |
],
|
| 45 |
"operators": [
|
| 46 |
+
{
|
| 47 |
+
"id": "ex_examples", "role": "operator", "kind": "dataset", "label": "Examples",
|
| 48 |
+
"dataset_id": "linoyts/subject-new-background-examples", "dataset_config": "default", "dataset_split": "train",
|
| 49 |
+
"inputs": [{"id": "row_index", "label": "row_index", "type": "number"}],
|
| 50 |
+
"outputs": [
|
| 51 |
+
{"id": "out_video", "label": "video", "type": "video"},
|
| 52 |
+
{"id": "out_prompt", "label": "prompt", "type": "text"}
|
| 53 |
+
],
|
| 54 |
+
"x": 320, "y": 40, "width": 280, "height": 220, "data": {"row_index": 0}
|
| 55 |
+
},
|
| 56 |
{
|
| 57 |
"id": "op_generate", "role": "operator", "kind": "fn", "source": "fn", "fn": "generate_video",
|
| 58 |
"label": "generate_video",
|
|
|
|
| 70 |
{"id": "out_1", "label": "alpha matte", "type": "video", "output_index": 1},
|
| 71 |
{"id": "out_2", "label": "background mask", "type": "video", "output_index": 2}
|
| 72 |
],
|
| 73 |
+
"x": 680, "y": 360, "width": 320, "height": 340, "data": {}
|
| 74 |
}
|
| 75 |
],
|
| 76 |
"subjects": [
|
|
|
|
| 78 |
"id": "sub_result", "role": "subject", "label": "Result", "asset_type": "video",
|
| 79 |
"inputs": [{"id": "in", "label": "Video", "type": "video"}],
|
| 80 |
"outputs": [{"id": "out", "label": "Video", "type": "video"}],
|
| 81 |
+
"x": 1120, "y": 220, "width": 300, "height": 220, "data": {}
|
| 82 |
},
|
| 83 |
{
|
| 84 |
"id": "sub_matte", "role": "subject", "label": "Alpha matte", "asset_type": "video",
|
| 85 |
"inputs": [{"id": "in", "label": "Video", "type": "video"}],
|
| 86 |
"outputs": [{"id": "out", "label": "Video", "type": "video"}],
|
| 87 |
+
"x": 1120, "y": 470, "width": 300, "height": 200, "data": {}
|
| 88 |
},
|
| 89 |
{
|
| 90 |
"id": "sub_mask", "role": "subject", "label": "Background mask", "asset_type": "video",
|
| 91 |
"inputs": [{"id": "in", "label": "Video", "type": "video"}],
|
| 92 |
"outputs": [{"id": "out", "label": "Video", "type": "video"}],
|
| 93 |
+
"x": 1120, "y": 700, "width": 300, "height": 200, "data": {}
|
| 94 |
}
|
| 95 |
],
|
| 96 |
"edges": [
|
| 97 |
+
{"id": "e_row", "from_node_id": "ref_row", "from_port_id": "out", "to_node_id": "ex_examples", "to_port_id": "row_index", "type": "number"},
|
| 98 |
+
{"id": "e_clip", "from_node_id": "ex_examples", "from_port_id": "out_video", "to_node_id": "op_generate", "to_port_id": "in_0", "type": "video"},
|
| 99 |
+
{"id": "e_prompt", "from_node_id": "ex_examples", "from_port_id": "out_prompt", "to_node_id": "op_generate", "to_port_id": "in_1", "type": "text"},
|
| 100 |
{"id": "e_relight", "from_node_id": "ref_relight", "from_port_id": "out", "to_node_id": "op_generate", "to_port_id": "in_2", "type": "number"},
|
| 101 |
{"id": "e_budget", "from_node_id": "ref_budget", "from_port_id": "out", "to_node_id": "op_generate", "to_port_id": "in_3", "type": "text"},
|
| 102 |
{"id": "e_steps", "from_node_id": "ref_steps", "from_port_id": "out", "to_node_id": "op_generate", "to_port_id": "in_4", "type": "number"},
|