Paul Jacob Logas
commited on
Commit
·
4bdc340
1
Parent(s):
e45d31c
Its done
Browse files- Dockerfile +2 -17
- app.py +112 -9
- environment.yaml +0 -123
- raccoon_emoji.png +0 -0
- requirements.txt +0 -1
- requirements_personal.txt +0 -2
Dockerfile
CHANGED
@@ -1,26 +1,11 @@
|
|
1 |
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
|
2 |
EXPOSE 7860
|
3 |
|
4 |
-
ENV CONDA_DIR /opt/conda
|
5 |
-
RUN apt-get update && \
|
6 |
-
apt-get install -y build-essential && \
|
7 |
-
apt-get install -y wget && \
|
8 |
-
apt-get install -y libgl1-mesa-glx && \
|
9 |
-
apt-get install -y libglib2.0-0 && \
|
10 |
-
apt-get clean && \
|
11 |
-
rm -rf /var/lib/apt/lists/*
|
12 |
-
|
13 |
-
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
|
14 |
-
/bin/bash ~/miniconda.sh -b -p /opt/conda
|
15 |
-
|
16 |
-
ENV PATH=$CONDA_DIR/bin:$PATH
|
17 |
-
|
18 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
19 |
WORKDIR /workspace
|
20 |
|
21 |
-
ADD
|
22 |
-
RUN
|
23 |
-
RUN pip install typing-extensions -U
|
24 |
|
25 |
ADD app.py /workspace/
|
26 |
CMD [ "python" , "/workspace/app.py" ]
|
|
|
1 |
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
|
2 |
EXPOSE 7860
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
5 |
WORKDIR /workspace
|
6 |
|
7 |
+
ADD requirements.txt /workspace/requirements.txt
|
8 |
+
RUN pip install -r requirements.txt
|
|
|
9 |
|
10 |
ADD app.py /workspace/
|
11 |
CMD [ "python" , "/workspace/app.py" ]
|
app.py
CHANGED
@@ -1,13 +1,116 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
-
|
6 |
-
# print(img)
|
7 |
-
fwks = Fawkes("extractor_2", '0', 1, mode=level)
|
8 |
-
fwks.run_protection([img], format='jpeg')
|
9 |
-
splt = img.split(".")
|
10 |
-
# print(os.listdir('/tmp'))
|
11 |
-
return splt[0] + "_cloaked." + splt[1]
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
from mtcnn_cv2 import MTCNN
|
5 |
import os
|
6 |
|
7 |
+
detector = MTCNN()
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
def predict(img, selection):
|
10 |
+
faces = detector.detect_faces(img)
|
11 |
+
|
12 |
+
privacy_fn = None
|
13 |
+
if(selection == "Low"):
|
14 |
+
opts = (anonymize_face_pixelate, 20)
|
15 |
+
elif(selection == "Medium"):
|
16 |
+
opts = (anonymize_face_pixelate, 10)
|
17 |
+
elif(selection == "High"):
|
18 |
+
opts = (anonymize_face_pixelate, 4)
|
19 |
+
elif(selection == "Emoji"):
|
20 |
+
opts = (anonymize_face_emoji, "smiley")
|
21 |
+
else:
|
22 |
+
raise Exception("I don't know how you did it but you chose something else.")
|
23 |
+
|
24 |
+
if len(faces) > 0:
|
25 |
+
for features in faces:
|
26 |
+
img = opts[0](img, features, opts[1])
|
27 |
+
else:
|
28 |
+
raise Exception("No faces detected");
|
29 |
+
return img
|
30 |
+
|
31 |
+
def anonymize_face_pixelate(image, features, blocks=10):
|
32 |
+
bb = features['box']
|
33 |
+
face_crop = image[bb[1]:bb[1]+bb[3], bb[0]:bb[0]+bb[2]]
|
34 |
+
# Divide the input image into NxN blocks
|
35 |
+
(h,w) = face_crop.shape[:2]
|
36 |
+
xSteps = np.linspace(0, w, blocks + 1, dtype="int")
|
37 |
+
ySteps = np.linspace(0, h, blocks + 1, dtype="int")
|
38 |
+
|
39 |
+
# loop over the blocks in both x and y direction
|
40 |
+
for i in range(1, len(ySteps)):
|
41 |
+
for j in range(1, len(xSteps)):
|
42 |
+
# compute starting and ending (x, y)-coordinates
|
43 |
+
# for current block
|
44 |
+
startX = xSteps[j - 1]
|
45 |
+
startY = ySteps[i - 1]
|
46 |
+
endX = xSteps[j]
|
47 |
+
endY = ySteps[i]
|
48 |
+
|
49 |
+
# Extract the ROI using NumPy array slicing, compute the
|
50 |
+
# mean of the ROI, and then draw a rectangle with the
|
51 |
+
# mean RGB values over the ROI in teh original image
|
52 |
+
roi = face_crop[startY:endY, startX:endX]
|
53 |
+
(B, G, R) = [int(x) for x in cv2.mean(roi)[:3]]
|
54 |
+
cv2.rectangle(face_crop, (startX, startY), (endX, endY),
|
55 |
+
(B,G,R), -1)
|
56 |
+
|
57 |
+
image[bb[1]:bb[1]+bb[3], bb[0]:bb[0]+bb[2]] = face_crop
|
58 |
+
return image
|
59 |
+
|
60 |
+
def anonymize_face_emoji(img, features, name="smiley"):
|
61 |
+
bb = features['box']
|
62 |
+
(y, x) = (bb[1] + int(bb[3]/2), bb[0] + int(bb[2]/2))
|
63 |
+
(h,w) = (bb[3], bb[2])
|
64 |
+
# Get emoji with transparency
|
65 |
+
mask = cv2.imread('raccoon_emoji.png', -1)
|
66 |
+
|
67 |
+
mshape = max(h,w)
|
68 |
+
offset = int(mshape/2)
|
69 |
+
|
70 |
+
return overlay_transparent(img, mask,
|
71 |
+
x - offset,
|
72 |
+
y - offset,
|
73 |
+
(mshape, mshape))
|
74 |
+
|
75 |
+
def overlay_transparent(background_img, img_to_overlay_t, x, y, overlay_size=None):
|
76 |
+
"""
|
77 |
+
@brief Overlays a transparant PNG onto another image using CV2
|
78 |
+
|
79 |
+
@param background_img The background image
|
80 |
+
@param img_to_overlay_t The transparent image to overlay (has alpha channel)
|
81 |
+
@param x x location to place the top-left corner of our overlay
|
82 |
+
@param y y location to place the top-left corner of our overlay
|
83 |
+
@param overlay_size The size to scale our overlay to (tuple), no scaling if None
|
84 |
+
|
85 |
+
@return Background image with overlay on top
|
86 |
+
"""
|
87 |
+
|
88 |
+
bg_img = background_img.copy()
|
89 |
+
|
90 |
+
if overlay_size is not None:
|
91 |
+
img_to_overlay_t = cv2.resize(img_to_overlay_t.copy(), overlay_size)
|
92 |
+
|
93 |
+
# Extract the alpha mask of the RGBA image, convert to RGB
|
94 |
+
b,g,r,a = cv2.split(img_to_overlay_t)
|
95 |
+
overlay_color = cv2.merge((b,g,r))
|
96 |
+
|
97 |
+
# Apply some simple filtering to remove edge noise
|
98 |
+
mask = cv2.medianBlur(a,5)
|
99 |
+
|
100 |
+
h, w, _ = overlay_color.shape
|
101 |
+
roi = bg_img[y:y+h, x:x+w]
|
102 |
+
|
103 |
+
# Black-out the area behind the logo in our original ROI
|
104 |
+
img1_bg = cv2.bitwise_and(roi.copy(),roi.copy(),mask = cv2.bitwise_not(mask))
|
105 |
+
|
106 |
+
# Mask out the logo from the logo image.
|
107 |
+
img2_fg = cv2.bitwise_and(overlay_color,overlay_color,mask = mask)
|
108 |
+
|
109 |
+
# Update the original image with our new ROI
|
110 |
+
bg_img[y:y+h, x:x+w] = cv2.add(img1_bg, img2_fg)
|
111 |
+
|
112 |
+
return bg_img
|
113 |
+
|
114 |
+
gr.Interface(fn=predict,
|
115 |
+
inputs=[gr.components.Image(type='numpy'), gr.components.Radio(["Low", "Medium", "High", "Emoji"], value="Medium")],
|
116 |
+
outputs=gr.components.Image(type="pil")).launch(show_error=True)
|
environment.yaml
DELETED
@@ -1,123 +0,0 @@
|
|
1 |
-
name: gradio
|
2 |
-
channels:
|
3 |
-
- nvidia
|
4 |
-
- conda-forge
|
5 |
-
- defaults
|
6 |
-
dependencies:
|
7 |
-
- _libgcc_mutex=0.1=main
|
8 |
-
- _openmp_mutex=5.1=1_gnu
|
9 |
-
- ca-certificates=2022.9.24=ha878542_0
|
10 |
-
- certifi=2022.9.24=pyhd8ed1ab_0
|
11 |
-
- cudatoolkit=11.0.221=h6bb024c_0
|
12 |
-
- cudnn=8.0.4=cuda11.0_0
|
13 |
-
- libedit=3.1.20210910=h7f8727e_0
|
14 |
-
- libffi=3.2.1=hf484d3e_1007
|
15 |
-
- libgcc-ng=11.2.0=h1234567_1
|
16 |
-
- libgomp=11.2.0=h1234567_1
|
17 |
-
- libstdcxx-ng=11.2.0=h1234567_1
|
18 |
-
- ncurses=6.3=h5eee18b_3
|
19 |
-
- openssl=1.1.1o=h166bdaf_0
|
20 |
-
- pip=22.2.2=py38h06a4308_0
|
21 |
-
- python=3.8.0=h0371630_2
|
22 |
-
- readline=7.0=h7b6447c_5
|
23 |
-
- setuptools=63.4.1=py38h06a4308_0
|
24 |
-
- sqlite=3.33.0=h62c20be_0
|
25 |
-
- tk=8.6.12=h1ccaba5_0
|
26 |
-
- wheel=0.37.1=pyhd3eb1b0_0
|
27 |
-
- xz=5.2.6=h5eee18b_0
|
28 |
-
- zlib=1.2.12=h5eee18b_3
|
29 |
-
- pip:
|
30 |
-
- absl-py==0.15.0
|
31 |
-
- aiohttp==3.8.3
|
32 |
-
- aiosignal==1.2.0
|
33 |
-
- analytics-python==1.4.0
|
34 |
-
- anyio==3.6.1
|
35 |
-
- astunparse==1.6.3
|
36 |
-
- async-timeout==4.0.2
|
37 |
-
- attrs==22.1.0
|
38 |
-
- backoff==1.10.0
|
39 |
-
- bcrypt==4.0.1
|
40 |
-
- bleach==5.0.1
|
41 |
-
- cachetools==5.2.0
|
42 |
-
- cffi==1.15.1
|
43 |
-
- charset-normalizer==2.1.1
|
44 |
-
- click==8.1.3
|
45 |
-
- contourpy==1.0.5
|
46 |
-
- cryptography==38.0.1
|
47 |
-
- cycler==0.11.0
|
48 |
-
- fastapi==0.76.0
|
49 |
-
- fawkes==1.0.4
|
50 |
-
- ffmpy==0.3.0
|
51 |
-
- flatbuffers==1.12
|
52 |
-
- fonttools==4.37.4
|
53 |
-
- frozenlist==1.3.1
|
54 |
-
- fsspec==2022.8.2
|
55 |
-
- gast==0.3.3
|
56 |
-
- google-auth==2.12.0
|
57 |
-
- google-auth-oauthlib==0.4.6
|
58 |
-
- google-pasta==0.2.0
|
59 |
-
- gradio==3.0.20
|
60 |
-
- grpcio==1.32.0
|
61 |
-
- h11==0.14.0
|
62 |
-
- h5py==2.10.0
|
63 |
-
- idna==3.4
|
64 |
-
- importlib-metadata==5.0.0
|
65 |
-
- jinja2==3.1.2
|
66 |
-
- keras==2.4.3
|
67 |
-
- keras-preprocessing==1.1.2
|
68 |
-
- kiwisolver==1.4.4
|
69 |
-
- linkify-it-py==1.0.3
|
70 |
-
- markdown==3.4.1
|
71 |
-
- markdown-it-py==2.1.0
|
72 |
-
- markupsafe==2.1.1
|
73 |
-
- matplotlib==3.6.1
|
74 |
-
- mdit-py-plugins==0.3.1
|
75 |
-
- mdurl==0.1.2
|
76 |
-
- monotonic==1.6
|
77 |
-
- mtcnn==0.1.1
|
78 |
-
- multidict==6.0.2
|
79 |
-
- numpy==1.19.5
|
80 |
-
- oauthlib==3.2.1
|
81 |
-
- opencv-python==4.6.0.66
|
82 |
-
- opt-einsum==3.3.0
|
83 |
-
- orjson==3.8.0
|
84 |
-
- packaging==21.3
|
85 |
-
- pandas==1.4.4
|
86 |
-
- paramiko==2.11.0
|
87 |
-
- pillow==9.2.0
|
88 |
-
- protobuf==3.19.6
|
89 |
-
- pyasn1==0.4.8
|
90 |
-
- pyasn1-modules==0.2.8
|
91 |
-
- pycparser==2.21
|
92 |
-
- pycryptodome==3.15.0
|
93 |
-
- pydantic==1.9.2
|
94 |
-
- pydub==0.25.1
|
95 |
-
- pynacl==1.5.0
|
96 |
-
- pyparsing==3.0.9
|
97 |
-
- python-dateutil==2.8.2
|
98 |
-
- python-multipart==0.0.5
|
99 |
-
- pytz==2022.4
|
100 |
-
- pyyaml==6.0
|
101 |
-
- requests==2.28.1
|
102 |
-
- requests-oauthlib==1.3.1
|
103 |
-
- rsa==4.9
|
104 |
-
- scipy==1.9.2
|
105 |
-
- six==1.15.0
|
106 |
-
- sniffio==1.3.0
|
107 |
-
- starlette==0.18.0
|
108 |
-
- tensorboard==2.10.1
|
109 |
-
- tensorboard-data-server==0.6.1
|
110 |
-
- tensorboard-plugin-wit==1.8.1
|
111 |
-
- tensorflow==2.4.1
|
112 |
-
- tensorflow-estimator==2.4.0
|
113 |
-
- termcolor==1.1.0
|
114 |
-
- typing-extensions
|
115 |
-
- uc-micro-py==1.0.1
|
116 |
-
- urllib3==1.26.12
|
117 |
-
- uvicorn==0.18.3
|
118 |
-
- webencodings==0.5.1
|
119 |
-
- werkzeug==2.2.2
|
120 |
-
- wrapt==1.12.1
|
121 |
-
- yarl==1.8.1
|
122 |
-
- zipp==3.9.0
|
123 |
-
prefix: /opt/conda/envs/gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raccoon_emoji.png
ADDED
![]() |
requirements.txt
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
fawkes==1.0.4
|
|
|
|
requirements_personal.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
gradio==3.0.20
|
2 |
-
fawkes==1.0.4
|
|
|
|
|
|