gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.6k stars 2.54k forks source link

ValueError: MultimodalTextbox expects a dictionary with optional keys #9087

Open zhouzaida opened 2 months ago

zhouzaida commented 2 months ago

Describe the bug

When I combined gr.Example with gr.MultimodalTextbox, it raised an error ValueError: MultimodalTextbox expects a dictionary with optional keys 'text' and 'files'. Received str if I updated the examples following the docs (https://www.gradio.app/docs/gradio/examples#examples). The reason is the Dataset can not work well with dict data. https://github.com/gradio-app/gradio/blob/62ed369efa6befac9a0eac736edcfa87a8d87a43/gradio/components/dataset.py#L102-L116

In addtion, if I printed the ex, I found it was text key.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

def update_examples():
    return gr.Dataset(samples=[{'text': 'gradio', 'files': ['path/of/image2']}])

with gr.Blocks() as demo:
    textbox = gr.MultimodalTextbox(show_label=False, placeholder="test", file_count='multiple', file_types=['image'])
    examples = gr.Examples([{'text': 'gradio', 'files': ['path/of/image1']}], textbox)
    update_btn = gr.Button(value="Update Examples")
    update_btn.click(update_examples, None, examples.dataset)

Screenshot

No response

Logs

No response

System Info

gradio                    4.41.0
gradio_client             1.3.0

Severity

I can work around it

import gradio as gr

def update_examples():
    # here is different
    # use an additional [] to wrap the {'text': 'gradio', 'files': ['path/of/image2']}
    return gr.Dataset(samples=[[{'text': 'gradio', 'files': ['path/of/image2']}]])

with gr.Blocks() as demo:
    textbox = gr.MultimodalTextbox(show_label=False, placeholder="test", file_count='multiple', file_types=['image'])
    examples = gr.Examples([{'text': 'gradio', 'files': ['path/of/image1']}], textbox)
    update_btn = gr.Button(value="Update Examples")
    update_btn.click(update_examples, None, examples.dataset)
abidlabs commented 2 months ago

Maybe related: https://github.com/gradio-app/gradio/issues/8971