2021-05-24 02:08:06 +08:00
|
|
|
import gradio as gr
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
CHOICES = ["foo", "bar", "baz"]
|
|
|
|
|
2021-10-01 02:20:54 +08:00
|
|
|
def fn(text1, text2, num, slider1, slider2, single_checkbox,
|
|
|
|
checkboxes, radio, dropdown, im1, im2, im3, im4, video, audio1,
|
|
|
|
audio2, file, df1, df2):
|
2021-05-24 02:08:06 +08:00
|
|
|
return (
|
2021-10-01 02:20:54 +08:00
|
|
|
(text1 if single_checkbox else text2) +
|
|
|
|
", selected:" + ", ".join(checkboxes), # Text
|
2021-05-24 02:08:06 +08:00
|
|
|
{
|
2021-10-01 02:20:54 +08:00
|
|
|
"positive": num / (num + slider1 + slider2),
|
|
|
|
"negative": slider1 / (num + slider1 + slider2),
|
|
|
|
"neutral": slider2 / (num + slider1 + slider2),
|
|
|
|
}, # Label
|
2021-12-17 18:52:19 +08:00
|
|
|
(audio1[0], np.flipud(audio1[1])) if audio1 is not None else "files/cantina.wav", # Audio
|
|
|
|
np.flipud(im1) if im1 is not None else "files/cheetah1.jpg", # Image
|
2021-10-01 02:20:54 +08:00
|
|
|
video, # Video
|
|
|
|
[("Height", 70), ("Weight", 150), ("BMI", "22"), (dropdown, 42)], # KeyValues
|
|
|
|
[("The", "art"), (" ", None), ("quick", "adj"), (" ", None),
|
|
|
|
("brown", "adj"), (" ", None), ("fox", "noun")], # HighlightedText
|
|
|
|
{"name": "Jane", "age": 34, "children": checkboxes}, # JSON
|
|
|
|
"<button style='background-color: red'>Click Me: " + radio + "</button>", # HTML
|
|
|
|
"files/titanic.csv",
|
|
|
|
np.ones((4, 3)), # Dataframe
|
2021-12-17 18:52:19 +08:00
|
|
|
[im for im in [im1, im2, im3, im4, "files/cheetah1.jpg"] if im is not None], # Carousel
|
2021-10-01 02:20:54 +08:00
|
|
|
df2 # Timeseries
|
2021-05-24 02:08:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
iface = gr.Interface(
|
|
|
|
fn,
|
|
|
|
inputs=[
|
2021-10-01 02:20:54 +08:00
|
|
|
gr.inputs.Textbox(default="Lorem ipsum", label="Textbox"),
|
|
|
|
gr.inputs.Textbox(lines=3, placeholder="Type here..",
|
|
|
|
label="Textbox 2"),
|
2021-05-24 02:08:06 +08:00
|
|
|
gr.inputs.Number(label="Number", default=42),
|
2021-10-01 02:20:54 +08:00
|
|
|
gr.inputs.Slider(minimum=10, maximum=20, default=15,
|
|
|
|
label="Slider: 10 - 20"),
|
|
|
|
gr.inputs.Slider(maximum=20, step=0.04,
|
|
|
|
label="Slider: step @ 0.04"),
|
2021-05-24 02:08:06 +08:00
|
|
|
gr.inputs.Checkbox(label="Checkbox"),
|
2021-10-01 02:20:54 +08:00
|
|
|
gr.inputs.CheckboxGroup(label="CheckboxGroup",
|
|
|
|
choices=CHOICES, default=CHOICES[0:2]),
|
|
|
|
gr.inputs.Radio(label="Radio", choices=CHOICES, default=CHOICES[2]),
|
2021-05-24 02:08:06 +08:00
|
|
|
gr.inputs.Dropdown(label="Dropdown", choices=CHOICES),
|
2021-09-03 05:01:28 +08:00
|
|
|
gr.inputs.Image(label="Image", optional=True),
|
2021-10-01 02:20:54 +08:00
|
|
|
gr.inputs.Image(label="Image w/ Cropper",
|
|
|
|
tool="select", optional=True),
|
|
|
|
gr.inputs.Image(label="Sketchpad", source="canvas", optional=True),
|
|
|
|
gr.inputs.Image(label="Webcam", source="webcam", optional=True),
|
2021-09-03 05:01:28 +08:00
|
|
|
gr.inputs.Video(label="Video", optional=True),
|
|
|
|
gr.inputs.Audio(label="Audio", optional=True),
|
2021-10-01 02:20:54 +08:00
|
|
|
gr.inputs.Audio(label="Microphone",
|
|
|
|
source="microphone", optional=True),
|
2021-09-03 05:01:28 +08:00
|
|
|
gr.inputs.File(label="File", optional=True),
|
|
|
|
gr.inputs.Dataframe(),
|
2021-10-01 02:20:54 +08:00
|
|
|
gr.inputs.Timeseries(x="time", y="value", optional=True),
|
2021-05-24 02:08:06 +08:00
|
|
|
],
|
|
|
|
outputs=[
|
2021-12-21 09:20:29 +08:00
|
|
|
gr.outputs.Textbox(label="Textbox"),
|
|
|
|
gr.outputs.Label(label="Label"),
|
|
|
|
gr.outputs.Audio(label="Audio"),
|
|
|
|
gr.outputs.Image(label="Image"),
|
|
|
|
gr.outputs.Video(label="Video"),
|
|
|
|
gr.outputs.KeyValues(label="KeyValues"),
|
|
|
|
gr.outputs.HighlightedText(label="HighlightedText"),
|
|
|
|
gr.outputs.JSON(label="JSON"),
|
|
|
|
gr.outputs.HTML(label="HTML"),
|
|
|
|
gr.outputs.File(label="File"),
|
|
|
|
gr.outputs.Dataframe(label="Dataframe"),
|
|
|
|
gr.outputs.Carousel("image", label="Carousel"),
|
|
|
|
gr.outputs.Timeseries(x="time", y="value", label="Timeseries")
|
2021-05-24 02:08:06 +08:00
|
|
|
],
|
2021-10-21 06:16:09 +08:00
|
|
|
theme="huggingface",
|
|
|
|
title="Kitchen Sink",
|
|
|
|
description="Try out all the components!",
|
|
|
|
article="Learn more about [Gradio](http://gradio.app)"
|
2021-05-24 02:08:06 +08:00
|
|
|
)
|
|
|
|
|
2021-06-30 03:04:22 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
iface.launch()
|