{"record":{"id":"d3c5385f2d3cffac","repo":"lllyasviel/Fooocus","slug":"invalid-value-for-parameter-type-type-please","errorCode":null,"errorMessage":"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}","messagePattern":"Invalid value for parameter `type`: (.+?)\\. Please choose from one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/gradio_hijack.py","lineNumber":127,"sourceCode":"            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.\n            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.\n            visible: If False, component will be hidden.\n            streaming: If True when used in a `live` interface, will automatically stream webcam feed. Only valid is source is 'webcam'.\n            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.\n            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.\n            mirror_webcam: If True webcam will be mirrored. Default is True.\n            brush_radius: Size of the brush for Sketch. Default is None which chooses a sensible default\n            brush_color: Color of the brush for Sketch as hex string. Default is \"#000000\".\n            mask_opacity: Opacity of mask drawn on image, as a value between 0 and 1.\n            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.\n        \"\"\"\n        self.brush_radius = brush_radius\n        self.brush_color = brush_color\n        self.mask_opacity = mask_opacity\n        self.mirror_webcam = mirror_webcam\n        valid_types = [\"numpy\", \"pil\", \"filepath\"]\n        if type not in valid_types:\n            raise ValueError(\n                f\"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}\"\n            )\n        self.type = type\n        self.shape = shape\n        self.height = height\n        self.width = width\n        self.image_mode = image_mode\n        valid_sources = [\"upload\", \"webcam\", \"canvas\"]\n        if source not in valid_sources:\n            raise ValueError(\n                f\"Invalid value for parameter `source`: {source}. Please choose from one of: {valid_sources}\"\n            )\n        self.source = source\n        if tool is None:\n            self.tool = \"sketch\" if source == \"canvas\" else \"editor\"\n        else:\n            self.tool = tool\n        self.invert_colors = invert_colors","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/gradio_hijack.py#L109-L145","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use 'numpy' (ndarray), 'pil' (PIL.Image), or 'filepath' (temp file path string) exactly.","If you need a tensor, take type='numpy' and torch.from_numpy(arr) in your handler.","Pin/keep the gradio version compatible with this vendored component, since the hijack mirrors an old API."],"exampleFix":"# before\nimg = Image(type='tensor')\n# after\nimg = Image(type='numpy')  # convert to tensor in the handler","handlingStrategy":"validation","validationCode":"VALID = ('numpy', 'pil', 'filepath')\nassert type_ in VALID, f'Image type must be one of {VALID}'","typeGuard":"def is_gradio_image_type(v) -> bool:\n    return v in ('numpy', 'pil', 'filepath')","tryCatchPattern":null,"preventionTips":["Centralize component construction in one helper that validates type/source against the vendored gradio API.","Remember this Fooocus build ships an old gradio Image: check gradio_hijack.py, not gradio's current docs."],"tags":["gradio","ui","constructor-validation","version-compatibility"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}