예제 #1
0
파일: run.py 프로젝트: gradio-app/gradio
                          xaxis_title="Cases",
                          yaxis_title="Days Since Day 0")
        return fig
    else:
        source = ColumnDataSource(df)
        p = bk.figure(title="Outbreak in " + month,
                      x_axis_label="Cases",
                      y_axis_label="Days Since Day 0")
        for country in countries:
            p.line(x='day', y=country, line_width=2, source=source)
        item_text = json_item(p, "plotDiv")
        return item_text


inputs = [
    gr.Dropdown(["Matplotlib", "Plotly", "Bokeh"], label="Plot Type"),
    gr.Slider(minimum=1, maximum=4, default_value=3.2, label="R"),
    gr.Dropdown(["January", "February", "March", "April", "May"],
                label="Month"),
    gr.CheckboxGroup(["USA", "Canada", "Mexico", "UK"],
                     label="Countries",
                     default_selected=["USA", "Canada"]),
    gr.Checkbox(label="Social Distancing?"),
]
outputs = gr.Plot(type="auto")

demo = gr.Interface(fn=outbreak, inputs=inputs, outputs=outputs)

if __name__ == "__main__":
    demo.launch()
예제 #2
0
파일: run.py 프로젝트: gradio-app/gradio
    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()
예제 #3
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()
예제 #4
0
파일: run.py 프로젝트: gradio-app/gradio
import gradio as gr


def filter_records(records, gender):
    return records[records["gender"] == gender]


demo = gr.Interface(
    filter_records,
    [
        gr.Dataframe(
            headers=["name", "age", "gender"],
            datatype=["str", "number", "str"],
            row_count=5,
        ),
        gr.Dropdown(["M", "F", "O"]),
    ],
    "dataframe",
    description="Enter gender as 'M', 'F', or 'O' for other.",
)

if __name__ == "__main__":
    demo.launch()
예제 #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"),
        gr.Audio(label="Audio"),
예제 #6
0
파일: run.py 프로젝트: gradio-app/gradio
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()
예제 #7
0
        "Company":
        [(1 if "Sibling" in company else 0) + (2 if "Child" in company else 0)
         ],
        "Fare": [fare],
        "Embarked": [embark_point + 1],
    })
    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,