Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -69,22 +69,6 @@ def mosaic(image, block_size):
|
|
69 |
return image
|
70 |
|
71 |
|
72 |
-
# Gradio
|
73 |
-
input_image = gr.Image(type="numpy", label="input image")
|
74 |
-
method = gr.Radio(
|
75 |
-
choices=["default", "灰階", "反轉顏色", "erosion", "dilation", "模糊", "馬賽克" ,"邊緣檢測1(Sobel)", "邊緣檢測2(Canny)", "風格變換"],
|
76 |
-
value="default",
|
77 |
-
label="選擇操作方法")
|
78 |
-
|
79 |
-
iterations = gr.Slider(minimum=0, maximum=10, step=1, value=1, label="參數大小", visible=False)
|
80 |
-
blur_degree = gr.Slider(minimum=1, maximum=25, step=2, value=1, label="模糊程度", visible=False)
|
81 |
-
dilation_iterations = gr.Slider(minimum=0, maximum=10, step=1, value=1, label="參數大小", visible=False)
|
82 |
-
mosaic_block_size = gr.Slider(minimum=5, maximum=50, step=5, value=5, label="馬賽克塊大小", visible=False)
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
output_image = gr.Image(type="numpy", label="output image")
|
87 |
-
|
88 |
|
89 |
def apply_opencv_methods(input_image, method, iterations, blur_degree, dilation_iterations, mosaic_block_size):
|
90 |
if method == "default":
|
@@ -117,16 +101,7 @@ def update_slider_visibility(method):
|
|
117 |
gr.update(visible=(method == "dilation")),
|
118 |
gr.update(visible=(method == "馬賽克"))
|
119 |
)
|
120 |
-
|
121 |
-
examples = gr.Examples(
|
122 |
-
examples = [
|
123 |
-
["chikawa.jpg", "erosion",2,None, None, None],
|
124 |
-
["cat.jpg", "風格變換",None,None, None, None],
|
125 |
-
["pui.jpg", "模糊",None,15, None, None],
|
126 |
-
],
|
127 |
-
inputs=[input_image, method, iterations, blur_degree, dilation_iterations, mosaic_block_size],
|
128 |
-
label="範例圖片",
|
129 |
-
)
|
130 |
with gr.Blocks() as demo:
|
131 |
input_image = gr.Image(type="numpy", label="input image")
|
132 |
method = gr.Radio(
|
@@ -139,14 +114,7 @@ with gr.Blocks() as demo:
|
|
139 |
mosaic_block_size = gr.Slider(minimum=5, maximum=50, step=5, value=5, label="馬賽克塊大小", visible=False)
|
140 |
output_image = gr.Image(type="numpy", label="output image")
|
141 |
|
142 |
-
|
143 |
-
examples=[
|
144 |
-
["chikawa.jpg", "erosion", 2, None, None, None],
|
145 |
-
["cat.jpg", "風格變換", None, None, None, None],
|
146 |
-
["pui.jpg", "模糊", None, 15, None, None]
|
147 |
-
],
|
148 |
-
inputs=[input_image, method, iterations, blur_degree, dilation_iterations, mosaic_block_size]
|
149 |
-
)
|
150 |
|
151 |
method.change(
|
152 |
fn=update_slider_visibility,
|
@@ -160,6 +128,16 @@ with gr.Blocks() as demo:
|
|
160 |
outputs=output_image,
|
161 |
live=True
|
162 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
demo.launch()
|
165 |
|
|
|
69 |
return image
|
70 |
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
def apply_opencv_methods(input_image, method, iterations, blur_degree, dilation_iterations, mosaic_block_size):
|
74 |
if method == "default":
|
|
|
101 |
gr.update(visible=(method == "dilation")),
|
102 |
gr.update(visible=(method == "馬賽克"))
|
103 |
)
|
104 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
with gr.Blocks() as demo:
|
106 |
input_image = gr.Image(type="numpy", label="input image")
|
107 |
method = gr.Radio(
|
|
|
114 |
mosaic_block_size = gr.Slider(minimum=5, maximum=50, step=5, value=5, label="馬賽克塊大小", visible=False)
|
115 |
output_image = gr.Image(type="numpy", label="output image")
|
116 |
|
117 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
method.change(
|
120 |
fn=update_slider_visibility,
|
|
|
128 |
outputs=output_image,
|
129 |
live=True
|
130 |
)
|
131 |
+
|
132 |
+
examples = gr.Examples(
|
133 |
+
examples=[
|
134 |
+
["chikawa.jpg", "erosion", 2, None, None, None],
|
135 |
+
["cat.jpg", "風格變換", None, None, None, None],
|
136 |
+
["pui.jpg", "模糊", None, 15, None, None]
|
137 |
+
],
|
138 |
+
inputs=[input_image, method, iterations, blur_degree, dilation_iterations, mosaic_block_size],
|
139 |
+
label="範例圖片",
|
140 |
+
)
|
141 |
|
142 |
demo.launch()
|
143 |
|