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