Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,6 @@ theme = gr.themes.Soft(
|
|
38 |
)
|
39 |
#----------End of theme----------
|
40 |
|
41 |
-
|
42 |
def flip_image(x):
|
43 |
return np.fliplr(x)
|
44 |
|
@@ -88,11 +87,28 @@ def classic_filter(image, filter_type):
|
|
88 |
|
89 |
elif filter_type == "Edge Detection":
|
90 |
edges = cv2.Canny(image, 100, 200)
|
91 |
-
return cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
|
92 |
|
93 |
-
def
|
94 |
"""Creative and unusual image filters"""
|
95 |
-
if filter_type == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
97 |
h, w = image.shape[:2]
|
98 |
for i in range(h):
|
@@ -130,7 +146,7 @@ def special_effects(image, filter_type):
|
|
130 |
|
131 |
elif filter_type == "Time Stamp":
|
132 |
output = image.copy()
|
133 |
-
timestamp = datetime.now().strftime("%
|
134 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
135 |
cv2.putText(output, timestamp, (10, 30), font, 1, (255, 255, 255), 2)
|
136 |
return output
|
@@ -231,23 +247,23 @@ def image_processing(image, filter_type):
|
|
231 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
232 |
|
233 |
# Process by filter categories
|
234 |
-
basic_filter_list = ["
|
235 |
-
|
236 |
creative_filters_list = ["Rainbow", "Night Vision"]
|
237 |
-
special_effects_list = ["Matrix Effect", "Wave Effect", "Time Stamp,
|
238 |
-
|
239 |
atmospheric_filters_list = ["Autumn", "Nostalgia", "Increase Brightness"]
|
240 |
|
241 |
if filter_type in basic_filter_list:
|
242 |
output = basic_filter(image, filter_type)
|
243 |
elif filter_type in classic_filter_list:
|
244 |
-
output =
|
245 |
-
elif filter_type in
|
246 |
output = creative_filters(image, filter_type)
|
247 |
elif filter_type in special_effects_list:
|
248 |
output = special_effects(image, filter_type)
|
249 |
elif filter_type in artistic_filters_list:
|
250 |
-
output = artistic_filters
|
251 |
elif filter_type in atmospheric_filters_list:
|
252 |
output = atmospheric_filters(image, filter_type)
|
253 |
else:
|
@@ -255,17 +271,18 @@ def image_processing(image, filter_type):
|
|
255 |
|
256 |
return cv2.cvtColor(output, cv2.COLOR_BGR2RGB) if len(output.shape) == 3 else output
|
257 |
|
|
|
258 |
# Gradio interface
|
259 |
with gr.Blocks(theme=theme) as app:
|
260 |
-
gr.Markdown("Image
|
261 |
with gr.Tab("Flip Image"):
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
with gr.Tab("Image Filters"):
|
269 |
with gr.Row():
|
270 |
with gr.Column():
|
271 |
image_input = gr.Image(type="numpy", label="📸 Upload Photos")
|
@@ -273,30 +290,30 @@ with gr.Blocks(theme=theme) as app:
|
|
273 |
filter_type = gr.Radio(
|
274 |
[
|
275 |
# Basic Filters
|
276 |
-
"
|
277 |
-
#
|
278 |
-
"Charcoal Effect", "Sharpen", "
|
279 |
# Creative Filters
|
280 |
"Rainbow", "Night Vision",
|
281 |
# Special Effects
|
282 |
"Matrix Effect", "Wave Effect", "Time Stamp", "Glitch Effect",
|
283 |
# Artistic Filters
|
284 |
-
"Pop Art", "Oil Paint", "Cartoon",
|
285 |
-
#Atmospheric Filters
|
286 |
-
"Autumn", "Nostalgia", "
|
287 |
],
|
288 |
label="🎭 Select Filter",
|
289 |
info="Choose the magic effect you want"
|
290 |
)
|
291 |
submit_button = gr.Button("✨ Apply Filter", variant="primary")
|
292 |
-
|
293 |
with gr.Column():
|
294 |
image_output = gr.Image(label="🖼️ Filtered Photo")
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
|
302 |
app.launch(share=True)
|
|
|
38 |
)
|
39 |
#----------End of theme----------
|
40 |
|
|
|
41 |
def flip_image(x):
|
42 |
return np.fliplr(x)
|
43 |
|
|
|
87 |
|
88 |
elif filter_type == "Edge Detection":
|
89 |
edges = cv2.Canny(image, 100, 200)
|
90 |
+
return cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
|
91 |
|
92 |
+
def creative_filters(image, filter_type):
|
93 |
"""Creative and unusual image filters"""
|
94 |
+
if filter_type == "Pixel Art":
|
95 |
+
h, w = image.shape[:2]
|
96 |
+
piksel_size = 20
|
97 |
+
small = cv2.resize(image, (w//piksel_size, h//piksel_size))
|
98 |
+
return cv2.resize(small, (w, h), interpolation=cv2.INTER_NEAREST)
|
99 |
+
|
100 |
+
elif filter_type == "Mosaic Effect":
|
101 |
+
h, w = image.shape[:2]
|
102 |
+
mosaic_size = 30
|
103 |
+
for i in range(0, h, mosaic_size):
|
104 |
+
for j in range(0, w, mosaic_size):
|
105 |
+
roi = image[i:i+mosaic_size, j:j+mosaic_size]
|
106 |
+
if roi.size > 0:
|
107 |
+
color = np.mean(roi, axis=(0,1))
|
108 |
+
image[i:i+mosaic_size, j:j+mosaic_size] = color
|
109 |
+
return image
|
110 |
+
|
111 |
+
elif filter_type == "Rainbow":
|
112 |
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
113 |
h, w = image.shape[:2]
|
114 |
for i in range(h):
|
|
|
146 |
|
147 |
elif filter_type == "Time Stamp":
|
148 |
output = image.copy()
|
149 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
150 |
font = cv2.FONT_HERSHEY_SIMPLEX
|
151 |
cv2.putText(output, timestamp, (10, 30), font, 1, (255, 255, 255), 2)
|
152 |
return output
|
|
|
247 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
248 |
|
249 |
# Process by filter categories
|
250 |
+
basic_filter_list = ["Gray Toning", "Sepia", "X-ray", "Burn it"]
|
251 |
+
classic_filter_list = ["Charcoal Effect", "Sharpen", "Embossing", "Edge Detection"]
|
252 |
creative_filters_list = ["Rainbow", "Night Vision"]
|
253 |
+
special_effects_list = ["Matrix Effect", "Wave Effect", "Time Stamp", "Glitch Effect"]
|
254 |
+
artistic_filters_list = ["Pop Art", "Oil Paint", "Cartoon Film"]
|
255 |
atmospheric_filters_list = ["Autumn", "Nostalgia", "Increase Brightness"]
|
256 |
|
257 |
if filter_type in basic_filter_list:
|
258 |
output = basic_filter(image, filter_type)
|
259 |
elif filter_type in classic_filter_list:
|
260 |
+
output = classic_filter(image, filter_type)
|
261 |
+
elif filter_type in creative_filters_list:
|
262 |
output = creative_filters(image, filter_type)
|
263 |
elif filter_type in special_effects_list:
|
264 |
output = special_effects(image, filter_type)
|
265 |
elif filter_type in artistic_filters_list:
|
266 |
+
output = artistic_filters(image, filter_type)
|
267 |
elif filter_type in atmospheric_filters_list:
|
268 |
output = atmospheric_filters(image, filter_type)
|
269 |
else:
|
|
|
271 |
|
272 |
return cv2.cvtColor(output, cv2.COLOR_BGR2RGB) if len(output.shape) == 3 else output
|
273 |
|
274 |
+
|
275 |
# Gradio interface
|
276 |
with gr.Blocks(theme=theme) as app:
|
277 |
+
gr.Markdown("# 🎨 Image Studio")
|
278 |
with gr.Tab("Flip Image"):
|
279 |
+
with gr.Row():
|
280 |
+
image_input = gr.Image()
|
281 |
+
image_output = gr.Image(format="png")
|
282 |
+
with gr.Row():
|
283 |
+
image_button = gr.Button("Run", variant='primary')
|
284 |
+
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
285 |
+
with gr.Tab("Image Filters"):
|
286 |
with gr.Row():
|
287 |
with gr.Column():
|
288 |
image_input = gr.Image(type="numpy", label="📸 Upload Photos")
|
|
|
290 |
filter_type = gr.Radio(
|
291 |
[
|
292 |
# Basic Filters
|
293 |
+
"Gray Toning", "Sepia", "X-ray", "Burn it",
|
294 |
+
# Classic Filter
|
295 |
+
"Charcoal Effect", "Sharpen", "Embossing", "Edge Detection",
|
296 |
# Creative Filters
|
297 |
"Rainbow", "Night Vision",
|
298 |
# Special Effects
|
299 |
"Matrix Effect", "Wave Effect", "Time Stamp", "Glitch Effect",
|
300 |
# Artistic Filters
|
301 |
+
"Pop Art", "Oil Paint", "Cartoon Film",
|
302 |
+
# Atmospheric Filters
|
303 |
+
"Autumn", "Nostalgia", "Increase Brightness"
|
304 |
],
|
305 |
label="🎭 Select Filter",
|
306 |
info="Choose the magic effect you want"
|
307 |
)
|
308 |
submit_button = gr.Button("✨ Apply Filter", variant="primary")
|
309 |
+
|
310 |
with gr.Column():
|
311 |
image_output = gr.Image(label="🖼️ Filtered Photo")
|
312 |
+
|
313 |
+
submit_button.click(
|
314 |
+
image_processing,
|
315 |
+
inputs=[image_input, filter_type],
|
316 |
+
outputs=image_output
|
317 |
+
)
|
318 |
|
319 |
app.launch(share=True)
|