Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,40 @@
|
|
| 1 |
-
import
|
| 2 |
-
import numpy as np
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
def apply_blur(image):
|
| 6 |
-
return
|
| 7 |
|
| 8 |
def apply_invert(image):
|
| 9 |
-
return
|
| 10 |
|
| 11 |
def apply_sharpen(image):
|
| 12 |
-
|
| 13 |
-
return cv2.filter2D(image, -1, kernel)
|
| 14 |
|
| 15 |
def apply_black_white(image):
|
| 16 |
-
return
|
| 17 |
|
| 18 |
def apply_filter(image, filter_type):
|
| 19 |
-
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 20 |
-
|
| 21 |
if filter_type == 'blur':
|
| 22 |
-
|
| 23 |
elif filter_type == 'invert':
|
| 24 |
-
|
| 25 |
elif filter_type == 'sharpen':
|
| 26 |
-
|
| 27 |
elif filter_type == 'black & white':
|
| 28 |
-
|
| 29 |
else:
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
if len(result.shape) == 2:
|
| 33 |
-
result = cv2.cvtColor(result, cv2.COLOR_GRAY2BGR)
|
| 34 |
-
|
| 35 |
-
return cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
|
| 36 |
|
| 37 |
def run_interface():
|
| 38 |
filter_choices = ['blur', 'invert', 'sharpen', 'black & white']
|
| 39 |
|
| 40 |
interface = gr.Interface(
|
| 41 |
fn=apply_filter,
|
| 42 |
-
inputs=[gr.Image(type='
|
| 43 |
gr.Dropdown(filter_choices, label='Select Filter')],
|
| 44 |
-
outputs=gr.Image(type='
|
| 45 |
-
live=2
|
| 46 |
)
|
| 47 |
return interface
|
| 48 |
|
| 49 |
iface = run_interface()
|
| 50 |
-
iface.launch(
|
|
|
|
| 1 |
+
from PIL import Image, ImageFilter, ImageOps
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
def apply_blur(image):
|
| 5 |
+
return image.filter(ImageFilter.BLUR)
|
| 6 |
|
| 7 |
def apply_invert(image):
|
| 8 |
+
return ImageOps.invert(image.convert("RGB"))
|
| 9 |
|
| 10 |
def apply_sharpen(image):
|
| 11 |
+
return image.filter(ImageFilter.SHARPEN)
|
|
|
|
| 12 |
|
| 13 |
def apply_black_white(image):
|
| 14 |
+
return image.convert("L") # Convert to grayscale (black & white)
|
| 15 |
|
| 16 |
def apply_filter(image, filter_type):
|
|
|
|
|
|
|
| 17 |
if filter_type == 'blur':
|
| 18 |
+
return apply_blur(image)
|
| 19 |
elif filter_type == 'invert':
|
| 20 |
+
return apply_invert(image)
|
| 21 |
elif filter_type == 'sharpen':
|
| 22 |
+
return apply_sharpen(image)
|
| 23 |
elif filter_type == 'black & white':
|
| 24 |
+
return apply_black_white(image)
|
| 25 |
else:
|
| 26 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def run_interface():
|
| 29 |
filter_choices = ['blur', 'invert', 'sharpen', 'black & white']
|
| 30 |
|
| 31 |
interface = gr.Interface(
|
| 32 |
fn=apply_filter,
|
| 33 |
+
inputs=[gr.Image(type='pil'),
|
| 34 |
gr.Dropdown(filter_choices, label='Select Filter')],
|
| 35 |
+
outputs=gr.Image(type='pil')
|
|
|
|
| 36 |
)
|
| 37 |
return interface
|
| 38 |
|
| 39 |
iface = run_interface()
|
| 40 |
+
iface.launch()
|