Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .github/workflows/sync_to_hub.yml +25 -0
- .gitignore +8 -8
- Dockerfile +1 -1
- 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-
|
| 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 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
```
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
```
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
```bash
|
| 40 |
-
python
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
``
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
```
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
```
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
#
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
```python
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
###
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 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 |
+

|
| 142 |
+
|
| 143 |
+
### Output Image/Video
|
| 144 |
+
#### Blur Masking
|
| 145 |
+

|
| 146 |
+
|
| 147 |
+
#### Emoji Masking
|
| 148 |
+

|
| 149 |
+
|
| 150 |
+
#### Text Masking
|
| 151 |
+

|
| 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 |
+
|