Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return of older bug. Cannot update Dataset #8312

Open
1 task done
Solomin0 opened this issue May 17, 2024 · 1 comment
Open
1 task done

Return of older bug. Cannot update Dataset #8312

Solomin0 opened this issue May 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Solomin0
Copy link

Solomin0 commented May 17, 2024

Describe the bug

@abidlabs
Unable to update the dataset object correctly. It seems like all the threads on this are closed or before 4.0 using the old .update methods.
#2143
Any help or workarounds would be great thanks.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr
def update(name):

    print(name)
    # new_examples = gr.Examples(["1","2","3"], inputs=[inp],label = "Saved Prompts")
    # return f"Welcome to Gradio, {name}!", new_examples
    return [["a"],["b"]]
with gr.Blocks() as demo:
    with gr.Row():
        inp = gr.Textbox(placeholder="What is your name?")

        saved_examples = gr.Dataset(components = ["text"], samples = [["This is my Favorite Prompt"]],label= "Saved Prompts" )

        saved_examples.click(update, inputs=[saved_examples], outputs=[saved_examples])
    # btn.click(fn=update, inputs=inp, outputs=[ex])

demo.launch()

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 4.31.0
gradio_client version: 0.16.2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.3.0
fastapi: 0.111.0
ffmpy: 0.3.2
gradio-client==0.16.2 is not installed.
httpx: 0.27.0
huggingface-hub: 0.23.0
importlib-resources: 6.4.0
jinja2: 3.1.4
markupsafe: 2.1.5
matplotlib: 3.8.4
numpy: 1.26.4
orjson: 3.10.3
packaging: 23.2
pandas: 2.2.2
pillow: 10.3.0
pydantic: 2.7.1
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.4.4
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.3
typing-extensions: 4.11.0
urllib3: 2.2.1
uvicorn: 0.29.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.3.1
httpx: 0.27.0
huggingface-hub: 0.23.0
packaging: 23.2
typing-extensions: 4.11.0
websockets: 11.0.3

Severity

I can work around it

@Solomin0 Solomin0 added the bug Something isn't working label May 17, 2024
@TranPhu1999
Copy link

Hi @Solomin0 according to your code I guess you are trying to build a simple UI that can save input text as examples for future use. In that case you can try this code:

import gradio as gr

examples = []

def update(input):
    examples.append([input])
    return examples

def fill_input(index):
    return examples[index][0]

with gr.Blocks() as demo:
    with gr.Row():
        inp = gr.Textbox(placeholder="What is your name?")

        saved_examples = gr.Dataset(components = ["text"], samples = examples,label= "Saved Prompts", type = "index")
        btn = gr.Button("Save Prompt")

    saved_examples.click(fill_input, inputs=[saved_examples], outputs=[inp])
    btn.click(fn=update, inputs=[inp], outputs=[saved_examples])
    # btn.click(fn=update, inputs=inp, outputs=[ex])

demo.launch()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants