赞
踩
PS:Gradio需要Python 3.8或更高版本,pip install gradio
- import gradio as gr
-
- def greet(name):
- return "Hello " + name + "!"
-
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
-
- demo.launch()
- import gradio as gr
-
- def greet(name):
- return "Hello " + name + "!"
-
- demo = gr.Interface(
- fn=greet,
- inputs=gr.Textbox(lines=2, placeholder="Name Here..."),
- outputs="text",
- )
- demo.launch()
- import gradio as gr
-
- def greet(name, is_morning, temperature):
- salutation = "Good morning" if is_morning else "Good evening"
- greeting = f"{salutation} {name}. It is {temperature} degrees today"
- 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"],
- )
- demo.launch()
- 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()
- import random
- import gradio as gr
-
- def random_response(message, history):
- return random.choice(["Yes", "No"])
-
- demo = gr.ChatInterface(random_response)
-
- demo.launch()
- 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()
- 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()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。