Spaces:
Running
Running
File size: 1,942 Bytes
0bc3e46 1aa45bc 0bc3e46 b1023a7 0bc3e46 b1023a7 0bc3e46 1aa45bc 0bc3e46 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
"""A simple Gradio demo with multiple tabs and accordions."""
import gradio as gr
import numpy as np
def flip_text(x: str) -> str:
"""Flip the text vertically."""
return x[::-1]
def flip_image(x: np.ndarray) -> np.ndarray:
"""Flip an image vertically."""
return np.fliplr(x)
def greet(
name: str,
temperature: int,
is_morning: bool,
) -> str:
"""Greet the user with a message and the temperature in Celsius."""
salutation = "Good morning" if is_morning else "Good evening"
return f"{salutation} {name}. It is {temperature} degrees Celsius today."
with gr.Blocks() as demo:
gr.Markdown("Flip text or image files using this demo.")
with gr.Tab("Flip Text"):
text_input = gr.Textbox(label="Enter text to flip here")
text_output = gr.Textbox(label="Output text")
text_button = gr.Button("Flip")
with gr.Tab("Flip Image"):
with gr.Row():
image_input = gr.Image(label="Upload image to flip here")
image_output = gr.Image(label="Output image")
image_button = gr.Button("Flip")
with gr.Accordion("Open for More!", open=False):
gr.Markdown("You can add anything in a toggle.")
with gr.Row():
with gr.Column():
name_input = gr.Text(label="What is your name?")
temperature_input = gr.Slider(-20, 50, label="What is the temperature?")
is_morning = gr.Checkbox(label="Is it morning?")
greeting_button = gr.Button("Greet")
with gr.Column():
greeting_output = gr.Text()
text_button.click(flip_text, inputs=text_input, outputs=text_output)
image_button.click(flip_image, inputs=image_input, outputs=image_output)
greeting_button.click(
greet,
inputs=[name_input, temperature_input, is_morning],
outputs=greeting_output,
)
if __name__ == "__main__":
demo.launch()
|