lllyasviel/Fooocus · error · ValueError

Invalid value for parameter `type`: {type}. Please choose fr

Error message

Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}

What it means

modules/gradio_hijack.py vendors an old gradio Image component to patch Gradio inside Fooocus. Its constructor validates the type parameter (the format the component hands to prediction functions) against ['numpy', 'pil', 'filepath']; any other value raises ValueError at component construction, i.e. at UI build time before the app even starts.

Source

Thrown at modules/gradio_hijack.py:127

            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            interactive: if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output.
            visible: If False, component will be hidden.
            streaming: If True when used in a `live` interface, will automatically stream webcam feed. Only valid is source is 'webcam'.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            mirror_webcam: If True webcam will be mirrored. Default is True.
            brush_radius: Size of the brush for Sketch. Default is None which chooses a sensible default
            brush_color: Color of the brush for Sketch as hex string. Default is "#000000".
            mask_opacity: Opacity of mask drawn on image, as a value between 0 and 1.
            show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.
        """
        self.brush_radius = brush_radius
        self.brush_color = brush_color
        self.mask_opacity = mask_opacity
        self.mirror_webcam = mirror_webcam
        valid_types = ["numpy", "pil", "filepath"]
        if type not in valid_types:
            raise ValueError(
                f"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}"
            )
        self.type = type
        self.shape = shape
        self.height = height
        self.width = width
        self.image_mode = image_mode
        valid_sources = ["upload", "webcam", "canvas"]
        if source not in valid_sources:
            raise ValueError(
                f"Invalid value for parameter `source`: {source}. Please choose from one of: {valid_sources}"
            )
        self.source = source
        if tool is None:
            self.tool = "sketch" if source == "canvas" else "editor"
        else:
            self.tool = tool
        self.invert_colors = invert_colors

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Use 'numpy' (ndarray), 'pil' (PIL.Image), or 'filepath' (temp file path string) exactly.
  2. If you need a tensor, take type='numpy' and torch.from_numpy(arr) in your handler.
  3. Pin/keep the gradio version compatible with this vendored component, since the hijack mirrors an old API.

Example fix

# before
img = Image(type='tensor')
# after
img = Image(type='numpy')  # convert to tensor in the handler
Defensive patterns

Strategy: validation

Validate before calling

VALID = ('numpy', 'pil', 'filepath')
assert type_ in VALID, f'Image type must be one of {VALID}'

Type guard

def is_gradio_image_type(v) -> bool:
    return v in ('numpy', 'pil', 'filepath')

Prevention

When it happens

Trigger: Creating the hijacked Image with type='tensor', 'image', 'file', or 'PIL' (case matters) — e.g. when copying example code that targets a different gradio version.

Common situations: Upgrading gradio in requirements and finding example snippets no longer valid; writing a custom tab that instantiates gr.Image with a type string supported by newer gradio (like 'numpy' only) or by other libs.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/d3c5385f2d3cffac. Report an issue: GitHub.