Spaces:
Runtime error
Runtime error
danielquillanroxas
commited on
Commit
ยท
13ad668
1
Parent(s):
cce1215
changed stuff
Browse files
app.py
CHANGED
|
@@ -21,16 +21,15 @@ except Exception as e:
|
|
| 21 |
print(f"Error loading model: {e}")
|
| 22 |
model = None
|
| 23 |
|
| 24 |
-
def detect_and_blur(
|
| 25 |
"""Process and blur sensitive content in image"""
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
img_array = np.array(input_image)
|
| 32 |
else:
|
| 33 |
-
|
| 34 |
|
| 35 |
# Process the image
|
| 36 |
result_img = img_array.copy()
|
|
@@ -68,37 +67,35 @@ def detect_and_blur(input_image):
|
|
| 68 |
except Exception as e:
|
| 69 |
return img_array, f"Error: {str(e)}"
|
| 70 |
|
| 71 |
-
message = f"Detected and blurred {detections['faces']} faces and {detections['plates']} plates/text regions"
|
| 72 |
return result_img, message
|
| 73 |
|
| 74 |
-
# Create
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
iface = gr.Interface(
|
| 80 |
fn=detect_and_blur,
|
| 81 |
-
inputs=gr.Image(
|
| 82 |
outputs=[
|
| 83 |
-
gr.Image(
|
| 84 |
gr.Textbox(label="Detection Results")
|
| 85 |
],
|
| 86 |
title=title,
|
| 87 |
description=description,
|
| 88 |
-
theme=gr.themes.Base(),
|
| 89 |
-
allow_flagging="never",
|
| 90 |
-
# Use examples from URLs to avoid file permission issues
|
| 91 |
examples=[
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
)
|
| 97 |
|
| 98 |
-
# Launch
|
| 99 |
if __name__ == "__main__":
|
| 100 |
-
|
| 101 |
-
server_name="0.0.0.0",
|
| 102 |
-
server_port=7860,
|
| 103 |
-
share=False
|
| 104 |
-
)
|
|
|
|
| 21 |
print(f"Error loading model: {e}")
|
| 22 |
model = None
|
| 23 |
|
| 24 |
+
def detect_and_blur(image):
|
| 25 |
"""Process and blur sensitive content in image"""
|
| 26 |
+
# Handle different input types
|
| 27 |
+
if isinstance(image, np.ndarray):
|
| 28 |
+
img_array = image
|
| 29 |
+
elif isinstance(image, str):
|
| 30 |
+
img_array = np.array(Image.open(image).convert('RGB'))
|
|
|
|
| 31 |
else:
|
| 32 |
+
return None, "Invalid input type"
|
| 33 |
|
| 34 |
# Process the image
|
| 35 |
result_img = img_array.copy()
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
return img_array, f"Error: {str(e)}"
|
| 69 |
|
| 70 |
+
message = f"Detected and blurred {detections['faces']} faces and {detections['plates']} license plates/text regions"
|
| 71 |
return result_img, message
|
| 72 |
|
| 73 |
+
# Create example_images directory if it doesn't exist
|
| 74 |
+
os.makedirs("examples", exist_ok=True)
|
| 75 |
+
|
| 76 |
+
# Define the Gradio interface
|
| 77 |
+
title = "Privacy Protector: Automatic Blurring"
|
| 78 |
+
description = (
|
| 79 |
+
"Upload an image to automatically blur faces, license plates, and text for privacy protection.\n"
|
| 80 |
+
"This model uses YOLOv8 to detect and blur sensitive content."
|
| 81 |
+
)
|
| 82 |
|
| 83 |
+
interface = gr.Interface(
|
|
|
|
| 84 |
fn=detect_and_blur,
|
| 85 |
+
inputs=gr.Image(), # Accept any image
|
| 86 |
outputs=[
|
| 87 |
+
gr.Image(label="Processed Image"),
|
| 88 |
gr.Textbox(label="Detection Results")
|
| 89 |
],
|
| 90 |
title=title,
|
| 91 |
description=description,
|
|
|
|
|
|
|
|
|
|
| 92 |
examples=[
|
| 93 |
+
# Following your friend's format: list of single-item lists
|
| 94 |
+
['examples/example1.jpg'],
|
| 95 |
+
['examples/example2.jpg']
|
| 96 |
+
]
|
| 97 |
)
|
| 98 |
|
| 99 |
+
# Launch the app
|
| 100 |
if __name__ == "__main__":
|
| 101 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|