akhaliq HF Staff commited on
Commit
6adf256
·
1 Parent(s): 9484d97

Return serveable file dicts from fn nodes; enable hf_oauth

Browse files

call_fn JSON-serializes bound-function results verbatim (unlike call_space,
which rewrites local paths into {path,url,is_file} dicts), so the generated
mp4 never rendered on the canvas. Wrap the video output in the file-dict
shape with a /gradio_api/file= URL; the tempdir is already in allowed_paths.

Also add hf_oauth: true so visitors run workflows on their own inference
quota and the owner can edit the canvas.

Files changed (2) hide show
  1. README.md +1 -0
  2. app.py +22 -2
README.md CHANGED
@@ -5,6 +5,7 @@ colorFrom: gray
5
  colorTo: red
6
  sdk: gradio
7
  sdk_version: 6.28.0
 
8
  app_file: app.py
9
  python_version: "3.12"
10
  startup_duration_timeout: 1h
 
5
  colorTo: red
6
  sdk: gradio
7
  sdk_version: 6.28.0
8
+ hf_oauth: true
9
  app_file: app.py
10
  python_version: "3.12"
11
  startup_duration_timeout: 1h
app.py CHANGED
@@ -434,22 +434,42 @@ def _as_path(value):
434
  return value
435
 
436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
  def i2v(image, prompt, actions, negative_prompt=NEGATIVE_PROMPT,
438
  num_chunks=DEFAULT_CHUNKS, seed=42):
439
  """Image → video node: explore an uploaded scene with a scripted camera."""
440
- return generate_i2v(
441
  _as_path(image), prompt, actions, negative_prompt or NEGATIVE_PROMPT,
442
  int(num_chunks), int(seed),
443
  )
 
444
 
445
 
446
  def t2v(prompt, actions, negative_prompt=NEGATIVE_PROMPT,
447
  num_chunks=DEFAULT_CHUNKS, seed=42):
448
  """Text → video node: generate a world from text and explore it."""
449
- return generate_t2v(
450
  prompt, actions, negative_prompt or NEGATIVE_PROMPT,
451
  int(num_chunks), int(seed),
452
  )
 
453
 
454
 
455
  CSS = """
 
434
  return value
435
 
436
 
437
+ def _as_file(value):
438
+ """`call_fn` JSON-serializes bound-function results verbatim (only `call_space`
439
+ rewrites local paths into serveable file dicts), so media outputs must be returned
440
+ in the `{path, url, is_file}` shape the canvas renders. The video lives under the
441
+ system tempdir, which `Workflow.launch()` adds to `allowed_paths`."""
442
+ if not isinstance(value, str) or not os.path.exists(value):
443
+ return value
444
+ try:
445
+ from gradio_client import utils as client_utils
446
+
447
+ encoded = client_utils.encode_file_path(value)
448
+ except (ImportError, AttributeError):
449
+ import urllib.parse
450
+
451
+ encoded = urllib.parse.quote(os.path.abspath(value))
452
+ return {"path": value, "url": "/gradio_api/file=" + encoded, "is_file": True}
453
+
454
+
455
  def i2v(image, prompt, actions, negative_prompt=NEGATIVE_PROMPT,
456
  num_chunks=DEFAULT_CHUNKS, seed=42):
457
  """Image → video node: explore an uploaded scene with a scripted camera."""
458
+ video, info = generate_i2v(
459
  _as_path(image), prompt, actions, negative_prompt or NEGATIVE_PROMPT,
460
  int(num_chunks), int(seed),
461
  )
462
+ return _as_file(video), info
463
 
464
 
465
  def t2v(prompt, actions, negative_prompt=NEGATIVE_PROMPT,
466
  num_chunks=DEFAULT_CHUNKS, seed=42):
467
  """Text → video node: generate a world from text and explore it."""
468
+ video, info = generate_t2v(
469
  prompt, actions, negative_prompt or NEGATIVE_PROMPT,
470
  int(num_chunks), int(seed),
471
  )
472
+ return _as_file(video), info
473
 
474
 
475
  CSS = """