incendies Cursor commited on
Commit
906aee4
·
1 Parent(s): 25b40da

fix(upscaler): use gr.File() output so API receives single path string

Browse files

- FnNode output changed from gr.Image to gr.File to avoid list serialization
- image_to_filepath now handles dict and list-of-dict formats from Gradio

Co-authored-by: Cursor <cursoragent@cursor.com>

Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -18,24 +18,30 @@ bg_remover = GradioNode(
18
 
19
 
20
  def image_to_filepath(image):
21
- """Convert image input (list or path) to a single filepath string.
22
- Phips/Upscaler API expects 'filepath', but upstream nodes (e.g. INPUT Image) may pass a list."""
23
  if image is None:
24
  return None
25
  if isinstance(image, str):
26
  return image
 
 
27
  if isinstance(image, (list, tuple)) and len(image) > 0:
28
  first = image[0]
29
- return first if isinstance(first, str) else None
 
 
 
30
  return None
31
 
32
 
33
  # Helper node: normalizes image (list/path) → single filepath for APIs that require it (e.g. Phips/Upscaler)
 
34
  image_to_path = FnNode(
35
  image_to_filepath,
36
  name="Image to path (for Upscaler)",
37
  inputs={"image": gr.Image(label="Input Image")},
38
- outputs={"image": gr.Image(label="Image (filepath)", type="filepath")},
39
  )
40
 
41
  # 2. Image Upscaler
@@ -45,7 +51,7 @@ upscaler = GradioNode(
45
  api_name="/upscale_image",
46
  run_locally=False,
47
  inputs={
48
- "image": image_to_path.image,
49
  },
50
  outputs={
51
  "upscaled_image": gr.Image(label="Upscaled Image"),
 
18
 
19
 
20
  def image_to_filepath(image):
21
+ """Convert image input (list, dict, or path) to a single filepath string.
22
+ Phips/Upscaler API expects 'filepath', but upstream nodes may pass a list or dict."""
23
  if image is None:
24
  return None
25
  if isinstance(image, str):
26
  return image
27
+ if isinstance(image, dict) and "path" in image and isinstance(image["path"], str):
28
+ return image["path"]
29
  if isinstance(image, (list, tuple)) and len(image) > 0:
30
  first = image[0]
31
+ if isinstance(first, str):
32
+ return first
33
+ if isinstance(first, dict) and "path" in first and isinstance(first["path"], str):
34
+ return first["path"]
35
  return None
36
 
37
 
38
  # Helper node: normalizes image (list/path) → single filepath for APIs that require it (e.g. Phips/Upscaler)
39
+ # Use gr.File() so the value is passed as a single path string; gr.Image() can serialize as list and Upscaler expects filepath.
40
  image_to_path = FnNode(
41
  image_to_filepath,
42
  name="Image to path (for Upscaler)",
43
  inputs={"image": gr.Image(label="Input Image")},
44
+ outputs={"image": gr.File(label="Image path")},
45
  )
46
 
47
  # 2. Image Upscaler
 
51
  api_name="/upscale_image",
52
  run_locally=False,
53
  inputs={
54
+ "image": image_to_path.image, # single path from File output
55
  },
56
  outputs={
57
  "upscaled_image": gr.Image(label="Upscaled Image"),