Spaces:
Runtime error
Runtime error
Addimg app.py
Browse files- app.py +36 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageOps, ImageFilter
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
def apply_filter(image, filter_type):
|
| 7 |
+
# Convert PIL image to OpenCV image
|
| 8 |
+
img = np.array(image.convert("RGB"))
|
| 9 |
+
|
| 10 |
+
if filter_type == "Grayscale":
|
| 11 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
| 12 |
+
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
|
| 13 |
+
elif filter_type == "Invert":
|
| 14 |
+
img = cv2.bitwise_not(img)
|
| 15 |
+
elif filter_type == "Blur":
|
| 16 |
+
img = cv2.GaussianBlur(img, (15, 15), 0)
|
| 17 |
+
elif filter_type == "Edge Detection":
|
| 18 |
+
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
| 19 |
+
edges = cv2.Canny(gray, 100, 200)
|
| 20 |
+
img = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
|
| 21 |
+
|
| 22 |
+
return Image.fromarray(img)
|
| 23 |
+
|
| 24 |
+
# Gradio UI
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=apply_filter,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Image(type="pil"),
|
| 29 |
+
gr.Radio(["Grayscale", "Invert", "Blur", "Edge Detection"], label="Choose a filter")
|
| 30 |
+
],
|
| 31 |
+
outputs=gr.Image(type="pil"),
|
| 32 |
+
title="🖼️ Image Filter App",
|
| 33 |
+
description="Upload an image and apply various filters!"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pillow
|
| 3 |
+
opencv-python
|