Ejemplo n.º 1
0
import gradio as gr


def sentence_builder(quantity, animal, place, activity_list, morning):
    return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""


demo = gr.Interface(
    sentence_builder,
    [
        gr.Slider(minimum=2, maximum=20),
        gr.Dropdown(["cat", "dog", "bird"]),
        gr.Radio(["park", "zoo", "road"]),
        gr.CheckboxGroup(["ran", "swam", "ate", "slept"]),
        gr.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],
    ],
)

if __name__ == "__main__":
    demo.launch()
Ejemplo n.º 2
0
    x = np.arange(start_year, final_year + 1)
    year_count = x.shape[0]
    plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style]
    fig = plt.figure()
    ax = fig.add_subplot(111)
    for i, company in enumerate(companies):
        series = np.arange(0, year_count, dtype=float)
        series = series**2 * (i + 1)
        series += np.random.rand(year_count) * noise
        ax.plot(x, series, plt_format)
    if show_legend:
        plt.legend(companies)
    plt.close()
    return fig


demo = gr.Interface(
    stock_forecast,
    [
        gr.Radio([2025, 2030, 2035, 2040], label="Project to:"),
        gr.CheckboxGroup(["Google", "Microsoft", "Gradio"]),
        gr.Slider(minimum=1, maximum=100),
        "checkbox",
        gr.Dropdown(["cross", "line", "circle"], label="Style"),
    ],
    gr.Image(plot=True, label="forecast"),
)

if __name__ == "__main__":
    demo.launch()
Ejemplo n.º 3
0
import gradio as gr


def calculator(num1, operation, num2):
    if operation == "add":
        return num1 + num2
    elif operation == "subtract":
        return num1 - num2
    elif operation == "multiply":
        return num1 * num2
    elif operation == "divide":
        return num1 / num2


demo = gr.Interface(
    calculator,
    ["number",
     gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
    "number",
    live=True,
)

if __name__ == "__main__":
    demo.launch()
Ejemplo n.º 4
0
        if taxable_income > bracket:
            total_tax += (taxable_income - bracket) * rate / 100

    if marital_status == "Married":
        total_tax *= 0.75
    elif marital_status == "Divorced":
        total_tax *= 0.8

    return round(total_tax)


demo = gr.Interface(
    tax_calculator,
    [
        "number",
        gr.Radio(["Single", "Married", "Divorced"]),
        gr.Dataframe(
            headers=["Item", "Cost", "Deduct"],
            datatype=["str", "number", "bool"],
            label="Assets Purchased this Year",
        ),
    ],
    "number",
    examples=[
        [10000, "Married", [["Car", 5000, False], ["Laptop", 800, True]]],
        [80000, "Single", [["Suit", 800, True], ["Watch", 1800, False]]],
    ],
)

if __name__ == "__main__":
    demo.launch()
Ejemplo n.º 5
0
    )


demo = gr.Interface(
    fn,
    inputs=[
        gr.Textbox(default_value="Lorem ipsum", label="Textbox"),
        gr.Textbox(lines=3, placeholder="Type here..", label="Textbox 2"),
        gr.Number(label="Number", default=42),
        gr.Slider(minimum=10, maximum=20, default_value=15, label="Slider: 10 - 20"),
        gr.Slider(maximum=20, step=0.04, label="Slider: step @ 0.04"),
        gr.Checkbox(label="Checkbox"),
        gr.CheckboxGroup(
            label="CheckboxGroup", choices=CHOICES, default_selected=CHOICES[0:2]
        ),
        gr.Radio(label="Radio", choices=CHOICES, default_selected=CHOICES[2]),
        gr.Dropdown(label="Dropdown", choices=CHOICES),
        gr.Image(label="Image"),
        gr.Image(label="Image w/ Cropper", tool="select"),
        gr.Image(label="Sketchpad", source="canvas"),
        gr.Image(label="Webcam", source="webcam"),
        gr.Video(label="Video"),
        gr.Audio(label="Audio"),
        gr.Audio(label="Microphone", source="microphone"),
        gr.File(label="File"),
        gr.Dataframe(label="Dataframe", headers=["Name", "Age", "Gender"]),
        gr.Timeseries(x="time", y=["price", "value"]),
    ],
    outputs=[
        gr.Textbox(label="Textbox"),
        gr.Label(label="Label"),
Ejemplo n.º 6
0
import gradio as gr

with gr.Blocks() as demo:
    txt = gr.Textbox(label="Small Textbox", lines=1)
    txt = gr.Textbox(label="Large Textbox", lines=5)
    num = gr.Number(label="Number")
    check = gr.Checkbox(label="Checkbox")
    check_g = gr.CheckboxGroup(label="Checkbox Group",
                               choices=["One", "Two", "Three"])
    radio = gr.Radio(label="Radio", choices=["One", "Two", "Three"])
    drop = gr.Dropdown(label="Dropdown", choices=["One", "Two", "Three"])
    slider = gr.Slider(label="Slider")
    audio = gr.Audio()
    video = gr.Video()
    image = gr.Image()
    ts = gr.Timeseries()
    df = gr.Dataframe()
    html = gr.HTML()
    json = gr.JSON()
    md = gr.Markdown()
    label = gr.Label()
    highlight = gr.HighlightedText()
    # layout components are static only
    # carousel doesn't work like other components
    # carousel = gr.Carousel()

if __name__ == "__main__":
    demo.launch()
Ejemplo n.º 7
0
    })
    df = encode_age(df)
    df = encode_fare(df)
    pred = clf.predict_proba(df)[0]
    return {"Perishes": float(pred[0]), "Survives": float(pred[1])}


demo = gr.Interface(
    predict_survival,
    [
        gr.Dropdown(["first", "second", "third"], type="index"),
        "checkbox",
        gr.Slider(minimum=0, maximum=80),
        gr.CheckboxGroup(["Sibling", "Child"],
                         label="Travelling with (select all)"),
        gr.Number(),
        gr.Radio(["S", "C", "Q"], type="index"),
    ],
    "label",
    examples=[
        ["first", True, 30, [], 50, "S"],
        ["second", False, 40, ["Sibling", "Child"], 10, "Q"],
        ["third", True, 30, ["Child"], 20, "S"],
    ],
    interpretation="default",
    live=True,
)

if __name__ == "__main__":
    demo.launch()