gradio/demo/sentence_builder.py

28 lines
882 B
Python
Raw Normal View History

2020-08-22 05:20:05 +08:00
# Demo: (Slider, Dropdown, Radio, CheckboxGroup, Checkbox) -> (Textbox)
2020-06-10 08:00:30 +08:00
import gradio as gr
2020-08-28 23:56:03 +08:00
2020-08-20 05:27:22 +08:00
def sentence_builder(quantity, animal, place, activity_list, morning):
2020-08-15 03:34:26 +08:00
return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
2020-06-11 14:04:14 +08:00
2020-08-28 23:56:03 +08:00
io = gr.Interface(
sentence_builder,
[
gr.inputs.Slider(2, 20),
gr.inputs.Dropdown(["cat", "dog", "bird"]),
gr.inputs.Radio(["park", "zoo", "road"]),
gr.inputs.CheckboxGroup(["ran", "swam", "ate", "slept"]),
gr.inputs.Checkbox(label="Is it the morning?"),
],
"text",
examples=[
[2, "cat", "park", ["ran", "swam"], True],
[4, "dog", "zoo", ["ate", "swam"], False],
[10, "bird", "road", ["ran"], False],
[8, "cat", "zoo", ["ate"], True],
])
2020-09-22 03:07:27 +08:00
io.test_launch()
2020-08-28 23:56:03 +08:00
io.launch()