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()
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()
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()
def ct_model(diseases, img): time.sleep(3) return {disease: 0.1 for disease in diseases} with gr.Blocks() as demo: gr.Markdown( """ # Detect Disease From Scan With this model you can lorem ipsum - ipsum 1 - ipsum 2 """ ) disease = gr.CheckboxGroup( choices=["Covid", "Malaria", "Lung Cancer"], label="Disease to Scan For" ) with gr.Tabs(): with gr.TabItem("X-ray"): with gr.Row(): xray_scan = gr.Image() xray_results = gr.JSON() xray_run = gr.Button("Run") xray_progress = gr.StatusTracker(cover_container=True) xray_run.click( xray_model, inputs=[disease, xray_scan], outputs=xray_results, status_tracker=xray_progress, )
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()
], # 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"), gr.Dataframe(label="Dataframe", headers=["Name", "Age", "Gender"]), gr.Timeseries(x="time", y=["price", "value"]), ], outputs=[
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()
if generate_report: pdf = FPDF() pdf.add_page() pdf.set_font("Arial", size=15) pdf.cell(200, 10, txt="Disease Report", ln=1, align="C") pdf.cell(200, 10, txt="A Gradio Demo.", ln=2, align="C") pdf.output(report) return results, report if generate_report else None demo = gr.Interface( disease_report, [ "image", gr.CheckboxGroup([ "Cancer", "Rash", "Heart Failure", "Stroke", "Diabetes", "Pneumonia" ]), "checkbox", ], [ gr.Carousel(["text", "image"], label="Disease"), gr.File(label="Report"), ], title="Disease Report", description="Upload an Xray and select the diseases to scan for.", theme="grass", flagging_options=["good", "bad", "etc"], allow_flagging="auto", ) if __name__ == "__main__":
"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, ) if __name__ == "__main__": demo.launch()
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()