#!/usr/bin/env python # coding: utf-8 # In[1]: '''get_ipython().run_line_magic('load_ext', 'gradio') # In[4]: get_ipython().run_cell_magic('blocks', '', '\nimport gradio as gr\n\ngr.Markdown("# Greetings from Gradio!")\ninp = gr.Textbox(placeholder="What is your name?")\nout = gr.Textbox()\n\ninp.change(fn=lambda x: f"Welcome, {x}!", \n inputs=inp, \n outputs=out)\n') # In[5]: get_ipython().run_cell_magic('blocks', '', 'def greet(name):\n return "Hello " + name + "!"\n\ndemo = gr.Interface(fn=greet, inputs="text", outputs="text")\n \ndemo.launch() \n') # In[7]: import gradio as gr def greet(name): return "Hello " + name + "!" demo = gr.Interface( fn=greet, inputs=gr.Textbox(lines=4, placeholder="Name Here..."), outputs="text", ) demo.launch() # In[15]: import gradio as gr def greet(yourname, is_morning, temperature): salutation = "Good morning" if is_morning else "Good evening" greeting = f"{salutation} {name}. It is {temperature} degrees Fahrenheit today." celsius = (temperature - 32) * 5 / 9 return greeting, round(celsius, 2) demo = gr.Interface( fn=greet, inputs=["text", "checkbox", gr.Slider(-50, 100)], outputs=["text", "number"], ) demo.launch() # In[16]: import numpy as np import gradio as gr def sepia(input_img): sepia_filter = np.array([ [0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131] ]) sepia_img = input_img.dot(sepia_filter.T) sepia_img /= sepia_img.max() return sepia_img demo = gr.Interface(sepia, gr.Image(shape=(200, 200)), "image") demo.launch() # In[18]: import gradio as gr def greet(name): return "Hello " + name + "!" with gr.Blocks() as demo: name = gr.Textbox(label="Name") output = gr.Textbox(label="Output Box") greet_btn = gr.Button("Greet") greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet") demo.launch()''' # In[19]: import numpy as np import gradio as gr def flip_text(x): return x[::-1] def flip_image(x): return np.fliplr(x) with gr.Blocks() as demo: gr.Markdown("Flip text or image files using this demo.") with gr.Tab("Flip Text"): text_input = gr.Textbox() text_output = gr.Textbox() text_button = gr.Button("Flip") with gr.Tab("Flip Image"): with gr.Row(): image_input = gr.Image() image_output = gr.Image() image_button = gr.Button("Flip") with gr.Accordion("Open for More!"): gr.Markdown("Look at me...") text_button.click(flip_text, inputs=text_input, outputs=text_output) image_button.click(flip_image, inputs=image_input, outputs=image_output) demo.launch() # In[26]: '''get_ipython().system(' pip install nbconvert -U') # In[27]: get_ipython().system('jupyter nbconvert --to script app.ipynb')'''