Spaces:
Sleeping
Sleeping
Commit
•
aaac77b
1
Parent(s):
f11aabe
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,91 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
"""
|
5 |
-
def greet(name, intensity):
|
6 |
-
return "Hello " + name * intensity + "!"
|
7 |
-
|
8 |
-
demo = gr.Interface(
|
9 |
-
fn=greet,
|
10 |
-
inputs=[gr.Textbox(), gr.Slider()],
|
11 |
-
outputs=["text"],
|
12 |
-
)
|
13 |
-
|
14 |
-
demo.launch()
|
15 |
-
"""
|
16 |
-
|
17 |
-
def image_mod(image):
|
18 |
-
return image.rotate(45)
|
19 |
-
|
20 |
-
|
21 |
-
demo = gr.Interface(
|
22 |
-
image_mod,
|
23 |
-
gr.Image(type="pil"),
|
24 |
-
"image",
|
25 |
-
flagging_options=["blurry", "incorrect", "other"],
|
26 |
-
examples=[
|
27 |
-
os.path.join(os.path.dirname(__file__), "images/cheetah1.jpg"),
|
28 |
-
os.path.join(os.path.dirname(__file__), "images/lion.jpg"),
|
29 |
-
os.path.join(os.path.dirname(__file__), "images/logo.png"),
|
30 |
-
os.path.join(os.path.dirname(__file__), "images/tower.jpg"),
|
31 |
-
],
|
32 |
-
)
|
33 |
|
34 |
-
if __name__ == "__main__":
|
35 |
-
demo.launch()
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
import gradio as gr
|
3 |
+
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
5 |
|
6 |
+
def get_random_color(rng):
|
7 |
+
for i in range(1):
|
8 |
+
color1 = rng.integers(low=0, high=255, size=(1, 1, 3))
|
9 |
+
color2 = rng.integers(low=0, high=255, size=(1, 1, 3))
|
10 |
+
color3 = rng.integers(low=0, high=255, size=(1, 1, 3))
|
11 |
+
color4 = rng.integers(low=0, high=255, size=(1, 1, 3))
|
12 |
+
block1 = np.concatenate((color1, color2), axis=0)
|
13 |
+
#print(f"Shape of block: {block1.shape}")
|
14 |
+
block2 = np.concatenate((color3, color4), axis=0)
|
15 |
+
#print(f"Shape of block: {block2.shape}")
|
16 |
+
block3 = np.concatenate((block1, block2), axis=1)
|
17 |
+
#print(f"Shape of block: {block3.shape}")
|
18 |
+
return color1, color2, color3, color4, block3
|
19 |
+
|
20 |
+
|
21 |
+
def color_me(num1):
|
22 |
+
# Make some random color
|
23 |
+
rng1 = np.random.default_rng(seed=num1)
|
24 |
+
return get_random_color(rng1)
|
25 |
+
|
26 |
+
|
27 |
+
def auto_color_me():
|
28 |
+
# Make some random color
|
29 |
+
# Get time to be the seed
|
30 |
+
seed = int(time.time())
|
31 |
+
rng1 = np.random.default_rng(seed=seed)
|
32 |
+
return get_random_color(rng1)
|
33 |
+
|
34 |
+
# Title of the blocks
|
35 |
+
with gr.Blocks() as demo1:
|
36 |
+
image_width = 64
|
37 |
+
image_height = 64
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
gr.Markdown(
|
41 |
+
"""
|
42 |
+
# Random color mix and match
|
43 |
+
|
44 |
+
The program displays four random colors and combined them together.
|
45 |
+
|
46 |
+
The color can be changed from the slider or text box. The same number \
|
47 |
+
will always give the same color.
|
48 |
+
|
49 |
+
The color can also be set to change automatically by the \
|
50 |
+
auto button. To stop the program, please close the browser tab.
|
51 |
+
|
52 |
+
The color can be downloaded from the download button at the top right \
|
53 |
+
corner to the image.
|
54 |
+
"""
|
55 |
+
)
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
num1 = gr.Slider(value=10, minimum=0, maximum=1000, step=1,
|
59 |
+
label="Value", info="Slide the bar or enter a value to change the color.")
|
60 |
+
|
61 |
+
with gr.Row():
|
62 |
+
btn_auto = gr.Button(value="Auto change color")
|
63 |
+
examples = gr.Examples(examples = [[82], [333], [590]], inputs=[num1])
|
64 |
+
|
65 |
+
|
66 |
+
with gr.Row():
|
67 |
+
with gr.Column():
|
68 |
+
color1 = gr.Image(height=image_height, width=image_width, show_label=False)
|
69 |
+
color2 = gr.Image(height=image_height, width=image_width, show_label=False)
|
70 |
+
color3 = gr.Image(height=image_height, width=image_width, show_label=False)
|
71 |
+
color4 = gr.Image(height=image_height, width=image_width, show_label=False)
|
72 |
+
with gr.Column():
|
73 |
+
image1 = gr.Image(height=image_height*4, width=image_width*4, show_label=False)
|
74 |
+
|
75 |
+
# Events
|
76 |
+
# Release of slider
|
77 |
+
num1.change(
|
78 |
+
fn=color_me,
|
79 |
+
inputs=[num1],
|
80 |
+
outputs=[color1, color2, color3, color4, image1]
|
81 |
+
)
|
82 |
+
# Clicking on auto change color
|
83 |
+
# Input = -1 indicate autochanging of color
|
84 |
+
btn_auto.click(fn=auto_color_me,
|
85 |
+
inputs=[],
|
86 |
+
outputs=[color1, color2, color3, color4, image1],
|
87 |
+
every=1)
|
88 |
+
|
89 |
+
# Main
|
90 |
+
if __name__ == "__main__":
|
91 |
+
demo1.launch()
|