Jacob Logas commited on
Commit
ebfeea8
·
unverified ·
1 Parent(s): be8e821

Update app with progress bar

Browse files
Files changed (2) hide show
  1. app.py +7 -19
  2. requirements.txt +95 -2
app.py CHANGED
@@ -1,10 +1,9 @@
1
  from fawkes.protection import Fawkes
2
- from fawkes.utils import Faces, reverse_process_cloaked, load_extractor
3
  from fawkes.differentiator import FawkesMaskGeneration
4
- from keras.preprocessing import image
5
  import numpy as np
6
  import gradio as gr
7
- from PIL import ExifTags
8
 
9
  IMG_SIZE = 112
10
  PREPROCESS = 'raw'
@@ -20,10 +19,10 @@ def generate_cloak_images(protector, image_X, target_emb=None):
20
 
21
  def predict(img, level, th=0.04, sd=1e7, lr=10, max_step=500, batch_size=1, format='png',
22
  separate_target=True, debug=False, no_align=False, exp="", maximize=True,
23
- save_last_on_failed=True):
24
 
25
  img = img.convert('RGB')
26
- img = image.img_to_array(img)
27
 
28
  if level == 'low':
29
  fwks = fwks_l
@@ -32,11 +31,9 @@ def predict(img, level, th=0.04, sd=1e7, lr=10, max_step=500, batch_size=1, form
32
  elif level == 'high':
33
  fwks = fwks_h
34
 
35
- # fwks = Fawkes("extractor_2", '0', 1, mode=level)
36
-
37
  current_param = "-".join([str(x) for x in [fwks.th, sd, fwks.lr, fwks.max_step, batch_size, format,
38
  separate_target, debug]])
39
- faces = Faces(['./Current Face'], [img], fwks.aligner, verbose=1, no_align=False)
40
  original_images = faces.cropped_faces
41
 
42
  if len(original_images) == 0:
@@ -57,7 +54,7 @@ def predict(img, level, th=0.04, sd=1e7, lr=10, max_step=500, batch_size=1, form
57
  learning_rate=fwks.lr,
58
  max_iterations=fwks.max_step,
59
  l_threshold=fwks.th,
60
- verbose=debug,
61
  maximize=maximize,
62
  keep_final=False,
63
  image_shape=(IMG_SIZE, IMG_SIZE, 3),
@@ -68,20 +65,11 @@ def predict(img, level, th=0.04, sd=1e7, lr=10, max_step=500, batch_size=1, form
68
  protected_images = generate_cloak_images(fwks.protector, original_images)
69
  faces.cloaked_cropped_faces = protected_images
70
 
71
- final_images, images_without_face = faces.merge_faces(
72
  reverse_process_cloaked(protected_images, preprocess=PREPROCESS),
73
  reverse_process_cloaked(original_images, preprocess=PREPROCESS))
74
 
75
- # print(final_images)
76
-
77
  return final_images[-1].astype(np.uint8)
78
- print("Done!")
79
-
80
-
81
- fwks.run_protection([img], format='jpeg')
82
- splt = img.split(".")
83
- # print(os.listdir('/tmp'))
84
- return splt[0] + "_cloaked.jpeg"
85
 
86
  gr.Interface(fn=predict, inputs=[gr.components.Image(type='pil'),
87
  gr.components.Radio(["low", "mid", "high"], label="Protection Level")],
 
1
  from fawkes.protection import Fawkes
2
+ from fawkes.utils import Faces, reverse_process_cloaked
3
  from fawkes.differentiator import FawkesMaskGeneration
4
+ import tensorflow as tf
5
  import numpy as np
6
  import gradio as gr
 
7
 
8
  IMG_SIZE = 112
9
  PREPROCESS = 'raw'
 
19
 
20
  def predict(img, level, th=0.04, sd=1e7, lr=10, max_step=500, batch_size=1, format='png',
21
  separate_target=True, debug=False, no_align=False, exp="", maximize=True,
22
+ save_last_on_failed=True, progress=gr.Progress(track_tqdm=True)):
23
 
24
  img = img.convert('RGB')
25
+ img = tf.keras.utils.img_to_array(img)
26
 
27
  if level == 'low':
28
  fwks = fwks_l
 
31
  elif level == 'high':
32
  fwks = fwks_h
33
 
 
 
34
  current_param = "-".join([str(x) for x in [fwks.th, sd, fwks.lr, fwks.max_step, batch_size, format,
35
  separate_target, debug]])
36
+ faces = Faces(['./Current Face'], [img], fwks.aligner, verbose=0, no_align=False)
37
  original_images = faces.cropped_faces
38
 
39
  if len(original_images) == 0:
 
54
  learning_rate=fwks.lr,
55
  max_iterations=fwks.max_step,
56
  l_threshold=fwks.th,
57
+ verbose=0,
58
  maximize=maximize,
59
  keep_final=False,
60
  image_shape=(IMG_SIZE, IMG_SIZE, 3),
 
65
  protected_images = generate_cloak_images(fwks.protector, original_images)
66
  faces.cloaked_cropped_faces = protected_images
67
 
68
+ final_images, _ = faces.merge_faces(
69
  reverse_process_cloaked(protected_images, preprocess=PREPROCESS),
70
  reverse_process_cloaked(original_images, preprocess=PREPROCESS))
71
 
 
 
72
  return final_images[-1].astype(np.uint8)
 
 
 
 
 
 
 
73
 
74
  gr.Interface(fn=predict, inputs=[gr.components.Image(type='pil'),
75
  gr.components.Radio(["low", "mid", "high"], label="Protection Level")],
requirements.txt CHANGED
@@ -1,2 +1,95 @@
1
- gradio>=3.21.0
2
- fawkes @ git+https://github.com/logasja/fawkes@master
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ absl-py==2.1.0
2
+ aiofiles==23.2.1
3
+ altair==5.3.0
4
+ annotated-types==0.7.0
5
+ anyio==3.7.1
6
+ astunparse==1.6.3
7
+ attrs==23.2.0
8
+ cachetools==5.3.3
9
+ certifi==2024.2.2
10
+ charset-normalizer==3.3.2
11
+ click==8.1.7
12
+ contourpy==1.2.1
13
+ cycler==0.12.1
14
+ fastapi==0.103.2
15
+ fawkes @ git+https://github.com/logasja/fawkes@master
16
+ ffmpy==0.3.2
17
+ filelock==3.14.0
18
+ flatbuffers==24.3.25
19
+ fonttools==4.51.0
20
+ fsspec==2024.5.0
21
+ gast==0.4.0
22
+ google-auth==2.29.0
23
+ google-auth-oauthlib==1.0.0
24
+ google-pasta==0.2.0
25
+ gradio==4.31.5
26
+ gradio_client==0.16.4
27
+ grpcio==1.64.0
28
+ h11==0.14.0
29
+ h5py==3.11.0
30
+ httpcore==1.0.5
31
+ httpx==0.27.0
32
+ huggingface-hub==0.23.1
33
+ idna==3.7
34
+ importlib_resources==6.4.0
35
+ Jinja2==3.1.4
36
+ jsonschema==4.22.0
37
+ jsonschema-specifications==2023.12.1
38
+ keras==2.13.1
39
+ kiwisolver==1.4.5
40
+ libclang==18.1.1
41
+ Markdown==3.6
42
+ markdown-it-py==3.0.0
43
+ MarkupSafe==2.1.5
44
+ matplotlib==3.9.0
45
+ mdurl==0.1.2
46
+ mtcnn==0.1.1
47
+ numpy==1.24.3
48
+ oauthlib==3.2.2
49
+ opencv-python==4.9.0.80
50
+ opt-einsum==3.3.0
51
+ orjson==3.10.3
52
+ packaging==24.0
53
+ pandas==2.2.2
54
+ Pillow==10.0.0
55
+ protobuf==4.25.3
56
+ pyasn1==0.6.0
57
+ pyasn1_modules==0.4.0
58
+ pydantic==2.7.1
59
+ pydantic_core==2.18.2
60
+ pydub==0.25.1
61
+ Pygments==2.18.0
62
+ pyparsing==3.1.2
63
+ python-dateutil==2.9.0.post0
64
+ python-multipart==0.0.9
65
+ pytz==2024.1
66
+ PyYAML==6.0.1
67
+ referencing==0.35.1
68
+ requests==2.32.2
69
+ requests-oauthlib==2.0.0
70
+ rich==13.7.1
71
+ rpds-py==0.18.1
72
+ rsa==4.9
73
+ ruff==0.4.4
74
+ semantic-version==2.10.0
75
+ shellingham==1.5.4
76
+ six==1.16.0
77
+ sniffio==1.3.1
78
+ starlette==0.27.0
79
+ tensorboard==2.13.0
80
+ tensorboard-data-server==0.7.2
81
+ tensorflow==2.13.0
82
+ tensorflow-estimator==2.13.0
83
+ tensorflow-io-gcs-filesystem==0.37.0
84
+ termcolor==2.4.0
85
+ tomlkit==0.12.0
86
+ toolz==0.12.1
87
+ tqdm==4.66.4
88
+ typer==0.12.3
89
+ typing_extensions==4.11.0
90
+ tzdata==2024.1
91
+ urllib3==2.2.1
92
+ uvicorn==0.29.0
93
+ websockets==11.0.3
94
+ Werkzeug==3.0.3
95
+ wrapt==1.16.0