Spaces:
Running
Running
"""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() | |