Spring-0 commited on
Commit
b166bcc
·
verified ·
1 Parent(s): 769b30e

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .github/workflows/sync_to_hub.yml +25 -0
  2. .gitignore +8 -8
  3. Dockerfile +1 -1
  4. README.md +181 -170
.github/workflows/sync_to_hub.yml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync with Hugging Face Hub
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout repo
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Install Hugging Face CLI
17
+ run: pip install -U "huggingface_hub[cli]"
18
+
19
+ - name: Upload to Hugging Face Space
20
+ env:
21
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
22
+ run: |
23
+ hf upload Spring-0/face-censor . . \
24
+ --repo-type space \
25
+ --token "$HF_TOKEN"
.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- __pycache__/
2
- *.pyc
3
- *.pyo
4
- src/runs/*
5
- src/yolov8n.pt
6
- src/data/raw
7
- .env
8
- .venv
9
  .gradio/
 
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ src/runs/*
5
+ src/yolov8n.pt
6
+ src/data/raw
7
+ .env
8
+ .venv
9
  .gradio/
Dockerfile CHANGED
@@ -2,7 +2,7 @@ FROM python:3.10
2
  WORKDIR /src
3
  COPY . /src
4
 
5
- RUN apt-get update && apt-get install -y libgl1-mesa-glx && rm -rf /var/lib/apt/lists/*
6
 
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
 
2
  WORKDIR /src
3
  COPY . /src
4
 
5
+ RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/*
6
 
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
README.md CHANGED
@@ -1,170 +1,181 @@
1
- ---
2
- title: face-censor
3
- sdk: docker
4
- pinned: false
5
- ---
6
- # Face Detection and Censoring System
7
-
8
- A Python-based system for detecting faces in images and videos using YOLOv8, with the ability to censor detected faces. The system is designed to be modular and extensible.
9
-
10
- ## Features
11
-
12
- - Face detection using YOLOv8
13
- - Support for both image and video processing
14
- - Easy to use User Interface
15
- - Modular censoring system
16
- - Trained on the WIDER FACE dataset via Roboflow
17
- - Multiple masking methods including: blur, emoji, and text (see [demo](#demo))
18
-
19
- ## Local Installation
20
-
21
- 1. Clone the repository:
22
- ```bash
23
- git clone https://github.com/Spring-0/face-censor.git
24
- cd face-censor
25
- ```
26
-
27
- 2. Create a virtual environment and activate it:
28
- ```bash
29
- python -m venv .venv
30
- source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
31
- ```
32
-
33
- 3. Install the required packages:
34
- ```bash
35
- pip install -r requirements.txt
36
- ```
37
-
38
- 4. Run:
39
- ```bash
40
- python src/main.py
41
- ```
42
-
43
- ## Training the Model - Optional
44
-
45
- The project uses the WIDER FACE dataset from Roboflow for training. I have included a pre-trained model, so there is no need to re-train it unless you want to. Here is how:
46
-
47
- 1. Update this line in `training/training.py` if required:
48
- ```python
49
- device="0" # Set to "0" to utilize GPU, otherwise set to "cpu" to utilize CPU
50
- ```
51
-
52
- 2. Create a `.env` file in the project root with your Roboflow API key:
53
- ```bash
54
- ROBOFLOW_API_KEY=your_api_key_here
55
- ```
56
-
57
- 3. Run the training script:
58
- ```bash
59
- cd training
60
- python3 training.py
61
- ```
62
-
63
- ## Usage
64
-
65
- ### API Usage
66
- ```python
67
- # Face detection model
68
- from models.yolo_detector import YOLOFaceDetector
69
-
70
- # Masking methods (no need to import all, just what you want to use)
71
- from masking.text import TextCensor
72
- from masking.emoji import EmojiCensor
73
- from masking.blur import BlurCensor
74
-
75
- # Media processor
76
- from processor import MediaProcessor
77
-
78
- # Initialize face detector model
79
- detector = YOLOFaceDetector()
80
- ```
81
- ### Creating Masking Object
82
- This is what determines what effect will be applied to mask the faces.
83
-
84
- #### Using Text Masking
85
- ```python
86
- text_censor = TextCensor(
87
- text="HELLO", # The text to draw on faces
88
- draw_background=True, # Control whether to draw solid background behind text
89
- background_color="white", # The color of the solid background
90
- text_color="black", # The color of the text
91
- scale_factor=0.2 # The text size scaling factor, default to 0.5
92
- )
93
- ```
94
- #### Using Emoji Masking
95
- ```python
96
- emoji_censor = EmojiCensor(
97
- emoji="😁", # The emoji you want to use to mask faces
98
- font="seguiemj.ttf", # The path to the emoji font file, by default uses "seguiemj.ttf"
99
- scale_factor=1.0 # The emoji size scaling factor in percentage, default to 1.0
100
- )
101
- ```
102
- #### Using Blur Masking
103
- ```python
104
- blur_censor = BlurCensor(
105
- blur_factor=71 # The strength of the blur effect, defaults to 99
106
- )
107
- ```
108
-
109
- ### Create Media Processor
110
- After creating the masking method object(s), you need to pass it to the `MediaProcessor` constructor like so:
111
- ```python
112
- processor = MediaProcessor(detector, blur_censor)
113
- ```
114
-
115
- ### Processing Images
116
- ```python
117
- # Process an image
118
- processor.process_image("input.jpg", "output.jpg")
119
- ```
120
-
121
- ### Processing Videos
122
- ```python
123
- # Process a video
124
- processor.process_video("input.mp4", "output.mp4")
125
- ```
126
-
127
- ## Demo
128
-
129
- ### Input Image/Video
130
- ![Input Image/Video](assets/input.jpg)
131
-
132
- ### Output Image/Video
133
- #### Blur Masking
134
- ![Output Blur Image/Video](assets/output_blur.jpg)
135
-
136
- #### Emoji Masking
137
- ![Output Emoji Image/Video](assets/output_emoji.jpg)
138
-
139
- #### Text Masking
140
- ![Output Text Image/Video](assets/output_text.jpg)
141
-
142
- ## Requirements
143
-
144
- - Python 3.8+
145
- - PyTorch
146
- - OpenCV
147
- - Ultralytics YOLOv8
148
- - Roboflow
149
-
150
- See `requirements.txt` for complete list.
151
-
152
- ## License
153
-
154
- GPU General Public License - see LICENSE file for details.
155
-
156
- ## Contributing
157
-
158
- 1. Fork the repository
159
- 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
160
- 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
161
- 4. Push to the branch (`git push origin feature/AmazingFeature`)
162
- 5. Open a Pull Request
163
-
164
- ## TODO
165
-
166
- - [x] Add emoji face masking
167
- - [ ] Add support for real time streams
168
- - [x] Add GUI interface
169
- - [ ] Add partial face censoring (eyes)
170
-
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ![Sync with HF Status](https://github.com/Spring-0/face-censor/actions/workflows/sync_to_hub.yml/badge.svg?branch=main)
2
+
3
+ # Face Detection and Censoring System
4
+
5
+ A Python-based system for detecting faces in images and videos using YOLOv8, with the ability to censor detected faces. The system is designed to be modular and extensible.
6
+
7
+ ## Features
8
+
9
+ - Face detection using YOLOv8
10
+ - Support for both image and video processing
11
+ - Easy to use User Interface
12
+ - Modular censoring system
13
+ - Trained on the WIDER FACE dataset via Roboflow
14
+ - Multiple masking methods including: blur, emoji, and text (see [demo](#demo))
15
+
16
+ ## Local Installation
17
+
18
+ ### With Docker 🐋
19
+ 1. Pull the image:
20
+ ```bash
21
+ docker pull spring93/face-censor
22
+ ```
23
+
24
+ 2. Run:
25
+ ```bash
26
+ docker run -p 3000:7860 -it --gpus all spring93/face-censor
27
+ ```
28
+
29
+ 3. Navigate to `http://localhost:3000` from your browser.
30
+
31
+ ### Without Docker
32
+ 1. Clone the repository:
33
+ ```bash
34
+ git clone https://github.com/Spring-0/face-censor.git
35
+ cd face-censor
36
+ ```
37
+
38
+ 2. Create a virtual environment and activate it:
39
+ ```bash
40
+ python -m venv .venv
41
+ source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
42
+ ```
43
+
44
+ 3. Install the required packages:
45
+ ```bash
46
+ pip install -r requirements.txt
47
+ ```
48
+
49
+ 4. Run:
50
+ ```bash
51
+ python src/main.py
52
+ ```
53
+
54
+ ## Training the Model - Optional
55
+
56
+ The project uses the WIDER FACE dataset from Roboflow for training. I have included a pre-trained model, so there is no need to re-train it unless you want to. Here is how:
57
+
58
+ 1. Update this line in `training/training.py` if required:
59
+ ```python
60
+ device="0" # Set to "0" to utilize GPU, otherwise set to "cpu" to utilize CPU
61
+ ```
62
+
63
+ 2. Create a `.env` file in the project root with your Roboflow API key:
64
+ ```bash
65
+ ROBOFLOW_API_KEY=your_api_key_here
66
+ ```
67
+
68
+ 3. Run the training script:
69
+ ```bash
70
+ cd training
71
+ python3 training.py
72
+ ```
73
+
74
+ ## Usage
75
+
76
+ ### API Usage
77
+ ```python
78
+ # Face detection model
79
+ from models.yolo_detector import YOLOFaceDetector
80
+
81
+ # Masking methods (no need to import all, just what you want to use)
82
+ from masking.text import TextCensor
83
+ from masking.emoji import EmojiCensor
84
+ from masking.blur import BlurCensor
85
+
86
+ # Media processor
87
+ from processor import MediaProcessor
88
+
89
+ # Initialize face detector model
90
+ detector = YOLOFaceDetector()
91
+ ```
92
+ ### Creating Masking Object
93
+ This is what determines what effect will be applied to mask the faces.
94
+
95
+ #### Using Text Masking
96
+ ```python
97
+ text_censor = TextCensor(
98
+ text="HELLO", # The text to draw on faces
99
+ draw_background=True, # Control whether to draw solid background behind text
100
+ background_color="white", # The color of the solid background
101
+ text_color="black", # The color of the text
102
+ scale_factor=0.2 # The text size scaling factor, default to 0.5
103
+ )
104
+ ```
105
+ #### Using Emoji Masking
106
+ ```python
107
+ emoji_censor = EmojiCensor(
108
+ emoji="😁", # The emoji you want to use to mask faces
109
+ font="seguiemj.ttf", # The path to the emoji font file, by default uses "seguiemj.ttf"
110
+ scale_factor=1.0 # The emoji size scaling factor in percentage, default to 1.0
111
+ )
112
+ ```
113
+ #### Using Blur Masking
114
+ ```python
115
+ blur_censor = BlurCensor(
116
+ blur_factor=71 # The strength of the blur effect, defaults to 99
117
+ )
118
+ ```
119
+
120
+ ### Create Media Processor
121
+ After creating the masking method object(s), you need to pass it to the `MediaProcessor` constructor like so:
122
+ ```python
123
+ processor = MediaProcessor(detector, blur_censor)
124
+ ```
125
+
126
+ ### Processing Images
127
+ ```python
128
+ # Process an image
129
+ processor.process_image("input.jpg", "output.jpg")
130
+ ```
131
+
132
+ ### Processing Videos
133
+ ```python
134
+ # Process a video
135
+ processor.process_video("input.mp4", "output.mp4")
136
+ ```
137
+
138
+ ## Demo
139
+
140
+ ### Input Image/Video
141
+ ![Input Image/Video](assets/input.jpg)
142
+
143
+ ### Output Image/Video
144
+ #### Blur Masking
145
+ ![Output Blur Image/Video](assets/output_blur.jpg)
146
+
147
+ #### Emoji Masking
148
+ ![Output Emoji Image/Video](assets/output_emoji.jpg)
149
+
150
+ #### Text Masking
151
+ ![Output Text Image/Video](assets/output_text.jpg)
152
+
153
+ ## Requirements
154
+
155
+ - Python 3.8+
156
+ - PyTorch
157
+ - OpenCV
158
+ - Ultralytics YOLOv8
159
+ - Roboflow
160
+
161
+ See `requirements.txt` for complete list.
162
+
163
+ ## License
164
+
165
+ GPU General Public License - see LICENSE file for details.
166
+
167
+ ## Contributing
168
+
169
+ 1. Fork the repository
170
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
171
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
172
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
173
+ 5. Open a Pull Request
174
+
175
+ ## TODO
176
+
177
+ - [x] Add emoji face masking
178
+ - [ ] Add support for real time streams
179
+ - [x] Add GUI interface
180
+ - [ ] Add partial face censoring (eyes)
181
+