Update app.py
Browse files
app.py
CHANGED
|
@@ -1,66 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
import cv2
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
filtered_img[:,:,1] = img[:,:,1]
|
| 37 |
-
elif filter_type == 'Blue':
|
| 38 |
-
filtered_img[:,:,2] = img[:,:,2]
|
| 39 |
-
elif filter_type == 'Green':
|
| 40 |
-
filtered_img[:,:,1] = img[:,:,1]
|
| 41 |
-
elif filter_type == 'Red':
|
| 42 |
-
filtered_img[:,:,0] = img[:,:,0]
|
| 43 |
-
elif filter_type == 'Cartoon':
|
| 44 |
-
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 45 |
-
blurImage = cv2.medianBlur(img, 1)
|
| 46 |
-
|
| 47 |
-
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9)
|
| 48 |
-
|
| 49 |
-
color = cv2.bilateralFilter(img, 9, 200, 200)
|
| 50 |
-
|
| 51 |
-
cartoon = cv2.bitwise_and(color, color, mask = edges)
|
| 52 |
-
|
| 53 |
-
filtered_img = cartoon
|
| 54 |
-
|
| 55 |
-
return filtered_img
|
| 56 |
-
|
| 57 |
-
demo = gr.Interface(filter_img,
|
| 58 |
-
inputs = [ gr.Image(type='numpy'),gr.Dropdown(["Cartoon","Gray","B&W","Sharp","Gray-sharp","Vintage","Magenta","Yellow","Cyan","Blue","Green","Red"])],
|
| 59 |
-
outputs=[
|
| 60 |
-
gr.Image(label="filter")
|
| 61 |
-
],
|
| 62 |
-
title = "Image Filterz",
|
| 63 |
-
description="Cool image filters!"
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
+
def sepia_filter(image):
|
| 6 |
+
"""
|
| 7 |
+
image comes in as a NumPy array (RGB)
|
| 8 |
+
"""
|
| 9 |
+
# Convert RGB (Gradio) → BGR (OpenCV)
|
| 10 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 11 |
+
|
| 12 |
+
sepia_kernel = np.array([
|
| 13 |
+
[0.272, 0.534, 0.131],
|
| 14 |
+
[0.349, 0.686, 0.168],
|
| 15 |
+
[0.393, 0.769, 0.189]
|
| 16 |
+
])
|
| 17 |
+
|
| 18 |
+
sepia = cv2.transform(image, sepia_kernel)
|
| 19 |
+
sepia = np.clip(sepia, 0, 255).astype(np.uint8)
|
| 20 |
+
|
| 21 |
+
# Convert back BGR → RGB for Gradio
|
| 22 |
+
sepia = cv2.cvtColor(sepia, cv2.COLOR_BGR2RGB)
|
| 23 |
+
|
| 24 |
+
return sepia
|
| 25 |
+
|
| 26 |
+
app = gr.Interface(
|
| 27 |
+
fn=sepia_filter,
|
| 28 |
+
inputs=gr.Image(type="numpy", label="Input Image"),
|
| 29 |
+
outputs=gr.Image(type="numpy", label="Sepia Output"),
|
| 30 |
+
title="Simple Sepia Filter",
|
| 31 |
+
description="Upload an image and apply a sepia filter using OpenCV."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|