def test_start_server(self): io = Interface(lambda x: x, "number", "number") io.favicon_path = None io.config = io.get_config_file() io.show_error = True io.flagging_callback.setup(gr.Number(), io.flagging_dir) io.auth = None port = networking.get_first_available_port( networking.INITIAL_PORT_VALUE, networking.INITIAL_PORT_VALUE + networking.TRY_NUM_PORTS, ) _, local_path, _, server = networking.start_server(io, server_port=port) url = urllib.parse.urlparse(local_path) self.assertEquals(url.scheme, "http") self.assertEquals(url.port, port) server.close()
import gradio as gr demo = gr.Blocks() with demo: gr.Textbox("Hello") gr.Number(5) if __name__ == "__main__": demo.launch()
"files/titanic.csv", 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"),
import gradio as gr def greet(name: str, repeat: int): return "Hello " + name * repeat + "!!" demo = gr.Interface(fn=greet, inputs=[gr.Textbox(lines=2, max_lines=4), gr.Number()], outputs=gr.component("textarea")) 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()
import gradio as gr test = gr.Blocks() with test: num = gr.Variable(default_value=0) squared = gr.Number(default_value=0) btn = gr.Button("Next Square") def increase(var): var += 1 return var, var**2 btn.click(increase, [num], [num, squared]) test.launch()
"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()
}) 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()