Spaces:
Runtime error
Runtime error
hadisalman
commited on
Commit
•
b04b973
1
Parent(s):
adc362f
Small fixes
Browse files
app.py
CHANGED
@@ -23,6 +23,7 @@ pipe_inpaint = pipe_inpaint.to("cuda")
|
|
23 |
## Good params for editing that we used all over the paper --> decent quality and speed
|
24 |
GUIDANCE_SCALE = 7.5
|
25 |
NUM_INFERENCE_STEPS = 100
|
|
|
26 |
|
27 |
def pgd(X, targets, model, criterion, eps=0.1, step_size=0.015, iters=40, clamp_min=0, clamp_max=1, mask=None):
|
28 |
X_adv = X.clone().detach() + (torch.rand(*X.shape)*2*eps-eps).cuda()
|
@@ -80,7 +81,10 @@ def immunize_fn(init_image, mask_image):
|
|
80 |
return adv_image
|
81 |
|
82 |
def run(image, prompt, seed, immunize=False):
|
83 |
-
seed
|
|
|
|
|
|
|
84 |
torch.manual_seed(seed)
|
85 |
|
86 |
init_image = Image.fromarray(image['image'])
|
@@ -111,9 +115,9 @@ def run(image, prompt, seed, immunize=False):
|
|
111 |
|
112 |
demo = gr.Interface(fn=run,
|
113 |
inputs=[
|
114 |
-
gr.ImageMask(label='Input Image'),
|
115 |
gr.Textbox(label='Prompt', placeholder='A photo of a man in a wedding'),
|
116 |
-
gr.Textbox(label='Seed', placeholder=
|
117 |
gr.Checkbox(label='Immunize', value=False),
|
118 |
],
|
119 |
cache_examples=False,
|
@@ -133,7 +137,7 @@ demo = gr.Interface(fn=run,
|
|
133 |
description='''<u>Official</u> demo of our paper: <br>
|
134 |
**Raising the Cost of Malicious AI-Powered Image Editing** <br>
|
135 |
*Hadi Salman\*, Alaa Khaddaj\*, Guillaume Leclerc\*, Andrew Ilyas, Aleksander Madry* <br>
|
136 |
-
[Paper](https://arxiv.org/abs/2302.06588)
|
137 |
[Blog post](https://gradientscience.org/photoguard/)
|
138 |
[![](https://badgen.net/badge/icon/GitHub?icon=github&label)](https://github.com/MadryLab/photoguard)
|
139 |
<br />
|
@@ -142,7 +146,7 @@ demo = gr.Interface(fn=run,
|
|
142 |
<br />
|
143 |
**Demo steps:**
|
144 |
+ Upload an image (or select from the below examples!)
|
145 |
-
+ Mask the parts of the image you want to maintain unedited (e.g., faces of people)
|
146 |
+ Add a prompt to edit the image accordingly (see examples below)
|
147 |
+ Play with the seed and click submit until you get a realistic edit that you are happy with (we have good seeds for you below)
|
148 |
|
|
|
23 |
## Good params for editing that we used all over the paper --> decent quality and speed
|
24 |
GUIDANCE_SCALE = 7.5
|
25 |
NUM_INFERENCE_STEPS = 100
|
26 |
+
DEFAULT_SEED = 1234
|
27 |
|
28 |
def pgd(X, targets, model, criterion, eps=0.1, step_size=0.015, iters=40, clamp_min=0, clamp_max=1, mask=None):
|
29 |
X_adv = X.clone().detach() + (torch.rand(*X.shape)*2*eps-eps).cuda()
|
|
|
81 |
return adv_image
|
82 |
|
83 |
def run(image, prompt, seed, immunize=False):
|
84 |
+
if seed == '':
|
85 |
+
seed = DEFAULT_SEED
|
86 |
+
else:
|
87 |
+
seed = int(seed)
|
88 |
torch.manual_seed(seed)
|
89 |
|
90 |
init_image = Image.fromarray(image['image'])
|
|
|
115 |
|
116 |
demo = gr.Interface(fn=run,
|
117 |
inputs=[
|
118 |
+
gr.ImageMask(label='Input Image (Use drawing tool to mask the regions you want to keep, e.g. faces)'),
|
119 |
gr.Textbox(label='Prompt', placeholder='A photo of a man in a wedding'),
|
120 |
+
gr.Textbox(label='Seed (Change to get different edits!)', placeholder=str(DEFAULT_SEED), visible=True),
|
121 |
gr.Checkbox(label='Immunize', value=False),
|
122 |
],
|
123 |
cache_examples=False,
|
|
|
137 |
description='''<u>Official</u> demo of our paper: <br>
|
138 |
**Raising the Cost of Malicious AI-Powered Image Editing** <br>
|
139 |
*Hadi Salman\*, Alaa Khaddaj\*, Guillaume Leclerc\*, Andrew Ilyas, Aleksander Madry* <br>
|
140 |
+
MIT [Paper](https://arxiv.org/abs/2302.06588)
|
141 |
[Blog post](https://gradientscience.org/photoguard/)
|
142 |
[![](https://badgen.net/badge/icon/GitHub?icon=github&label)](https://github.com/MadryLab/photoguard)
|
143 |
<br />
|
|
|
146 |
<br />
|
147 |
**Demo steps:**
|
148 |
+ Upload an image (or select from the below examples!)
|
149 |
+
+ Mask (with the drawing tool) the parts of the image you want to maintain unedited (e.g., faces of people)
|
150 |
+ Add a prompt to edit the image accordingly (see examples below)
|
151 |
+ Play with the seed and click submit until you get a realistic edit that you are happy with (we have good seeds for you below)
|
152 |
|