| |
|
|
| import gradio as gr |
|
|
|
|
| def update_ui(task): |
| return ( |
| gr.update(visible=task == "text"), |
| gr.update(visible=task == "image"), |
| gr.update(visible=task == "text"), |
| gr.update(visible=task == "image"), |
| ) |
|
|
|
|
| with gr.Blocks() as demo: |
| tasks = gr.Dropdown(choices=["text", "image"], value="text") |
| text = gr.Textbox() |
| image = gr.Image(height=400, visible=False) |
|
|
| with gr.Row() as text_examples: |
| gr.Examples(examples=["a", "b"], inputs=text) |
| with gr.Row(visible=False) as image_examples: |
| gr.Examples(examples=["dogs.jpg"], inputs=image) |
|
|
| tasks.change( |
| fn=update_ui, |
| inputs=tasks, |
| outputs=[ |
| text, |
| image, |
| text_examples, |
| image_examples, |
| ], |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| demo.queue().launch() |
|
|