lllyasviel/Fooocus · error · ValueError

Invalid value for parameter `source`: {source}. Please choos

Error message

Invalid value for parameter `source`: {source}. Please choose from one of: {valid_sources}

What it means

The same vendored gradio Image constructor validates source (where the image comes from) against ['upload', 'webcam', 'canvas']; anything else raises ValueError. Note this vendored version still supports source=, whereas gradio removed the parameter in 4.x — mixing APIs between versions is the usual cause.

Source

Thrown at modules/gradio_hijack.py:137

            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
        self.streaming = streaming
        self.show_download_button = show_download_button
        if streaming and source != "webcam":
            raise ValueError("Image streaming only available if source is 'webcam'.")
        self.select: EventListenerMethod
        """
        Event listener for when the user clicks on a pixel within the image.
        Uses event data gradio.SelectData to carry `index` to refer to the [x, y] coordinates of the clicked pixel.
        See EventData documentation on how to use this event data.
        """

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Use exactly 'upload', 'webcam', or 'canvas' for source.
  2. For sketch input use source='canvas' (tool defaults to 'sketch'); for plain upload use 'upload'.
  3. Do not feed gradio 3/4 example code into this vendored component — check modules/gradio_hijack.py's own signatures.

Example fix

# before
Image(source='sketch', tool='sketch')
# after
Image(source='canvas', tool='sketch')
Defensive patterns

Strategy: validation

Validate before calling

SOURCES = ('upload', 'webcam', 'canvas')
assert source in SOURCES, f'source must be one of {SOURCES}'

Type guard

def is_gradio_image_source(v) -> bool:
    return v in ('upload', 'webcam', 'canvas')

Prevention

When it happens

Trigger: Constructing Image(source='file'), source='camera', source='sketch', or source=None with the hijacked component; passing tool/source combinations from newer gradio examples.

Common situations: See trigger scenarios.

Related errors


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