danielquillanroxas commited on
Commit
13ad668
ยท
1 Parent(s): cce1215

changed stuff

Browse files
Files changed (1) hide show
  1. app.py +26 -29
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(input_image):
25
  """Process and blur sensitive content in image"""
26
- if input_image is None:
27
- return None, "Please upload an image"
28
-
29
- # Convert from Gradio format
30
- if isinstance(input_image, Image.Image):
31
- img_array = np.array(input_image)
32
  else:
33
- img_array = input_image
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 a simple interface
75
- title = "Privacy Protector: Blur Faces, Plates, and Text"
76
- description = "Upload an image to automatically blur faces, license plates, and text"
 
 
 
 
 
 
77
 
78
- # Use Interface instead of Blocks for more stability
79
- iface = gr.Interface(
80
  fn=detect_and_blur,
81
- inputs=gr.Image(type="numpy"),
82
  outputs=[
83
- gr.Image(type="numpy", label="Processed 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
- "https://raw.githubusercontent.com/ultralytics/yolov5/master/data/images/zidane.jpg",
93
- "https://raw.githubusercontent.com/ultralytics/ultralytics/main/docs/images/bus.jpg"
94
- ],
95
- cache_examples=False # Disable caching to avoid permission issues
96
  )
97
 
98
- # Launch with the correct server parameters for containerized environments
99
  if __name__ == "__main__":
100
- iface.launch(
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()