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

Be able to generate random samples in gr.Examples or examples in gr.ChatInterface #8325

Closed
1 task done
djstrong opened this issue May 18, 2024 · 4 comments · Fixed by #8745
Closed
1 task done

Be able to generate random samples in gr.Examples or examples in gr.ChatInterface #8325

djstrong opened this issue May 18, 2024 · 4 comments · Fixed by #8745
Labels
enhancement New feature or request

Comments

@djstrong
Copy link

djstrong commented May 18, 2024

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
I am using ChatInterface (https://huggingface.co/spaces/speakleash/Bielik-7B-Instruct-v0.1-test/blob/main/app.py) and want to sample examples with every page load.

Describe the solution you'd like
Maybe add sample_examples parameter to the ChatInterface?

Additional context
I tried load listener but without success.
Related issues: #5042 #8293

@abidlabs
Copy link
Member

Hi @djstrong if I understand correctly, you want to change the examples randomly every time the page loads?

@djstrong
Copy link
Author

Yes.

@abidlabs abidlabs changed the title Sample examples in ChatInterface Be able to generate random samples in gr.Examples or examples in gr.ChatInterface May 20, 2024
@abidlabs
Copy link
Member

I am working on a PR that will allow this to happen. You can test it by doing:

pip install https://gradio-builds.s3.amazonaws.com/c2dc8a1bd9585c3170a116d12a465be9223f1310/gradio-4.37.2-py3-none-any.whl

and then doing something like this:

import gradio as gr
import random

def update_examples():
    return gr.Dataset(samples=random.choice(
        [
            [["merhaba"], ["merhaba2"]],
            [["bonjour"], ["bonjour2"]]
        ]
    ))

with gr.Blocks() as demo:
    chat = gr.ChatInterface(lambda x,y:x, examples=[["hello"], ["hi"]])
    demo.load(update_examples, None, chat.examples_handler.dataset)
    
demo.launch()

@djstrong
Copy link
Author

@abidlabs Thanks. But it doesn't work correctly. After clicking an example button different text is provided. You can check here: https://huggingface.co/spaces/speakleash/Bielik-7B-Instruct-v0.1
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants