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()
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()
now = datetime.datetime.now() return now.strftime("%m/%d/%Y, %H:%M:%S") def generate_recording(): return random.choice(["new-sax-1.mp3", "new-sax-1.wav"]) def reconstruct(audio): return random.choice(["new-sax-1.mp3", "new-sax-1.wav"]) io1 = gr.Interface( lambda x, y, z: os.path.join(os.path.dirname(__file__), "sax.wav"), [ gr.Slider(label="pitch"), gr.Slider(label="loudness"), gr.Audio(label="base audio file (optional)"), ], gr.Audio(), ) io2 = gr.Interface( lambda x, y, z: os.path.join(os.path.dirname(__file__), "flute.wav"), [ gr.Slider(label="pitch"), gr.Slider(label="loudness"), gr.Audio(label="base audio file (optional)"), ], gr.Audio(), )
if column not in categories ] if len(drop_columns): card_activity.drop(columns=drop_columns, inplace=True) return ( card_activity, card_activity, { "fraud": activity_range / 100.0, "not fraud": 1 - activity_range / 100.0 }, ) demo = gr.Interface( fraud_detector, [ gr.Timeseries(x="time", y=["retail", "food", "other"]), gr.CheckboxGroup(["retail", "food", "other"], default_selected=["retail", "food", "other"]), gr.Slider(minimum=1, maximum=3), ], [ "dataframe", gr.Timeseries(x="time", y=["retail", "food", "other"]), gr.Label(label="Fraud Level"), ], ) if __name__ == "__main__": demo.launch()
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()
df1, # Dataframe np.random.randint(0, 10, (4, 4)), # Dataframe [ im for im in [im1, im2, im3, im4, "files/cheetah1.jpg"] if im is not None ], # Carousel df2, # Timeseries ) 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"),
theta = a / 180 * 3.14 tmax = ((2 * v) * np.sin(theta)) / g timemat = tmax * np.linspace(0, 1, 40)[:, None] x = (v * timemat) * np.cos(theta) y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2)) fig = plt.figure() plt.scatter(x=x, y=y, marker=".") plt.xlim(0, 100) plt.ylim(0, 60) return fig demo = gr.Blocks() with demo: gr.Markdown( "Let's do some kinematics! Choose the speed and angle to see the trajectory." ) with gr.Row(): speed = gr.Slider(25, min=1, max=30, label="Speed") angle = gr.Slider(45, min=0, max=90, label="Angle") output = gr.Image(type="plot") btn = gr.Button("Run") btn.click(plot, [speed, angle], output) if __name__ == "__main__": demo.launch()
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()
time.sleep(1) image = random.choice([ "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80", "https://images.unsplash.com/photo-1554151228-14d9def656e4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=386&q=80", "https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8aHVtYW4lMjBmYWNlfGVufDB8fDB8fA%3D%3D&w=1000&q=80", "https://images.unsplash.com/photo-1546456073-92b9f0a8d413?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80", "https://images.unsplash.com/photo-1601412436009-d964bd02edbc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80", ]) return image demo = gr.Interface( fn=fake_gan, inputs=[ gr.Image(label="Initial Image (optional)"), gr.Slider(25, minimum=0, maximum=50, label="TV_scale (for smoothness)"), gr.Slider(25, minimum=0, maximum=50, label="Range_Scale (out of range RBG)"), gr.Number(label="Seed"), gr.Number(label="Respacing"), ], outputs=gr.Image(label="Generated Image"), title="FD-GAN", description= "This is a fake demo of a GAN. In reality, the images are randomly chosen from Unsplash.", ) if __name__ == "__main__": demo.launch()
import gradio as gr def greet(name, is_morning, temperature): salutation = "Good morning" if is_morning else "Good evening" greeting = "%s %s. It is %s degrees today" % (salutation, name, temperature) celsius = (temperature - 32) * 5 / 9 return greeting, round(celsius, 2) demo = gr.Interface( fn=greet, inputs=["text", "checkbox", gr.Slider(0, 100)], outputs=["text", "number"], ) if __name__ == "__main__": demo.launch()
], "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, )
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( plot_forecast, [ gr.Radio([2025, 2030, 2035, 2040], label="Project to:"), gr.CheckboxGroup(["Google", "Microsoft", "Gradio"], label="Company Selection"), gr.Slider(minimum=1, maximum=100, label="Noise Level"), gr.Checkbox(label="Show Legend"), gr.Dropdown(["cross", "line", "circle"], label="Style"), ], gr.Image(plot=True, label="forecast"), ) if __name__ == "__main__": demo.launch()