Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import cv2
|
| 3 |
-
import numpy as np
|
| 4 |
-
|
| 5 |
-
def edge_detection(image, threshold1, threshold2):
|
| 6 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 7 |
-
edges = cv2.Canny(gray, threshold1, threshold2)
|
| 8 |
-
return edges
|
| 9 |
-
|
| 10 |
-
def image_segmentation(image):
|
| 11 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 12 |
-
_, segmented = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
| 13 |
-
return segmented
|
| 14 |
-
|
| 15 |
-
def image_inpainting(image, mask):
|
| 16 |
-
if mask.shape[:2] != image.shape[:2]:
|
| 17 |
-
mask = cv2.resize(mask, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)
|
| 18 |
-
|
| 19 |
-
if len(mask.shape) == 3:
|
| 20 |
-
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
|
| 21 |
-
mask = (mask > 0).astype(np.uint8) * 255
|
| 22 |
-
inpainted = cv2.inpaint(image, mask, 3, cv2.INPAINT_TELEA)
|
| 23 |
-
return inpainted
|
| 24 |
-
|
| 25 |
-
with gr.Blocks() as demo:
|
| 26 |
-
gr.Markdown("Computer Vision")
|
| 27 |
-
with gr.Tab("Edge Detection"):
|
| 28 |
-
inputs = [
|
| 29 |
-
gr.Image(type="numpy", label="Upload Image"),
|
| 30 |
-
gr.Slider(0, 255, value=50, step=1, label="Threshold 1"),
|
| 31 |
-
gr.Slider(0, 255, value=100, step=1, label="Threshold 2"),
|
| 32 |
-
]
|
| 33 |
-
output = gr.Image(type="numpy", label="Edge Image")
|
| 34 |
-
gr.Interface(
|
| 35 |
-
fn=edge_detection,
|
| 36 |
-
inputs=inputs,
|
| 37 |
-
outputs=output,
|
| 38 |
-
description="Upload an image and adjust the thresholds to perform edge detection"
|
| 39 |
-
)
|
| 40 |
-
with gr.Tab("Image Segmentation"):
|
| 41 |
-
inputs = [
|
| 42 |
-
gr.Image(type="numpy", label="Upload Image")
|
| 43 |
-
]
|
| 44 |
-
output = gr.Image(type="numpy", label="Segmented Image")
|
| 45 |
-
gr.Interface(
|
| 46 |
-
fn=image_segmentation,
|
| 47 |
-
inputs=inputs,
|
| 48 |
-
outputs=output,
|
| 49 |
-
description="Upload an image to perform image segmentation"
|
| 50 |
-
)
|
| 51 |
-
with gr.Tab("Image Inpainting"):
|
| 52 |
-
inputs = [
|
| 53 |
-
gr.Image(type="numpy", label="Upload Image"),
|
| 54 |
-
gr.Image(type="numpy", label="Upload Mask")
|
| 55 |
-
]
|
| 56 |
-
output = gr.Image(type="numpy", label="Inpainted Image")
|
| 57 |
-
gr.Interface(
|
| 58 |
-
fn=image_inpainting,
|
| 59 |
-
inputs=inputs,
|
| 60 |
-
outputs=output,
|
| 61 |
-
description="Upload an image and adjust the thresholds to perform image inpainting",
|
| 62 |
-
allow_flagging='never'
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
-
if __name__ == "__main__":
|
| 66 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|