The Radio component creates a set of radio buttons where only one option can be selected.
Basic usage
import gradio as gr
def respond(choice):
return f"You selected: {choice}"
gr.Interface(
fn=respond,
inputs=gr.Radio(["Option 1", "Option 2", "Option 3"]),
outputs=gr.Textbox()
).launch()
Constructor
choices
Sequence[str | int | float | tuple] | None
default:"None"
List of options. Can be values or (label, value) tuples
value
str | int | float | Callable | None
default:"None"
Default selected option. If None, no option is selected initially
type
Literal['value', 'index']
default:"'value'"
Return type:
"value" - Returns selected value
"index" - Returns selected index
Label displayed above component
Whether to display radio buttons right-to-left
Events
- select - Triggered when option is selected
- change - Triggered when selection changes
- input - Triggered on input
Example
import gradio as gr
gr.Radio(
choices=[
("Low (128x128)", "low"),
("Medium (256x256)", "medium"),
("High (512x512)", "high")
],
value="medium",
label="Resolution"
)