Skip to content

Cannot override upload image + sketch, NoneType attributeerror. #4088

@Symbiomatrix

Description

@Symbiomatrix

Describe the bug

I created an image component with source = upload, type = numpy, tool = sketch.
Then, attempted to override its upload method with a simple edit diversion.
However, this broke the regular upload functionality, with any simple png image (which obviously worked before) - apparently it's trying to read the mask content in components.preprocess, but doesn't have a fallback in case mask is None, as is the case for the input images I used.

A simple exception clause when setting mask_im should suffice, I think.
Another assertion breaks in preprocess if I set this image via another component's update: assert isinstance(x, dict) . For that one there at least seems to be a workaround of setting the component to a dict in the first place (with a null mask).
Actually looks like I can't, because postprocess expects only images, no dict. 🤦‍♂️
Note that the preprocess assertion error occurs after 2-3 overwrites, receives a base64 str.

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

import gradio as gr
def detect_image_colours(img):
    return img

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            sketch = gr.Image(source = "upload", mirror_webcam = False, type = "numpy", tool = "sketch")
    sketch.upload(fn = detect_image_colours, inputs = [sketch], outputs = [sketch])

if __name__ == "__main__":
    demo.launch()
  1. Attempt to upload png image to sketch component.

Screenshot

No response

Logs

Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\gradio\routes.py", line 338, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\Python38\lib\site-packages\gradio\blocks.py", line 1013, in process_api
    inputs = self.preprocess_data(fn_index, inputs, state)
  File "C:\Python38\lib\site-packages\gradio\blocks.py", line 911, in preprocess_data
    processed_input.append(block.preprocess(inputs[i]))
  File "C:\Python38\lib\site-packages\gradio\components.py", line 1508, in preprocess
    mask_im = processing_utils.decode_base64_to_image(mask)
  File "C:\Python38\lib\site-packages\gradio\processing_utils.py", line 53, in decode_base64_to_image
    content = encoding.split(";")[1]
AttributeError: 'NoneType' object has no attribute 'split'

System Info

Gradio = 3.16.2
OS = Windows 10
Browser = Chrome

Severity

annoying

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions