xinchen9 commited on
Commit
7ccf651
β€’
1 Parent(s): 4510837

[Update]Load files

Browse files
Files changed (7) hide show
  1. .gitattributes +35 -35
  2. README.md +13 -13
  3. about.py +90 -0
  4. app.py +127 -0
  5. css_html_js.py +105 -0
  6. images/cheetah.jpg +0 -0
  7. requirements.txt +14 -0
.gitattributes CHANGED
@@ -1,35 +1,35 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,13 @@
1
- ---
2
- title: UnlearnDiffAtk
3
- emoji: πŸ“ˆ
4
- colorFrom: red
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 4.36.1
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: SD Offense
3
+ emoji: πŸ“ˆ
4
+ colorFrom: yellow
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 4.33.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
about.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from enum import Enum
3
+
4
+ @dataclass
5
+ class Task:
6
+ benchmark: str
7
+ metric: str
8
+ col_name: str
9
+
10
+
11
+ # Select your tasks here
12
+ # ---------------------------------------------------
13
+ class Tasks(Enum):
14
+ # task_key in the json file, metric_key in the json file, name to display in the leaderboard
15
+ task0 = Task("anli_r1", "acc", "ANLI")
16
+ task1 = Task("logiqa", "acc_norm", "LogiQA")
17
+
18
+ NUM_FEWSHOT = 0 # Change with your few shot
19
+ # ---------------------------------------------------
20
+
21
+
22
+
23
+
24
+ # Your leaderboard name
25
+ TITLE = """<h1 align="center" id="space-title"> Demo of UnlearnDiffAtk</h1>"""
26
+
27
+ # subtitle
28
+ SUB_TITLE = """<h2 align="center" id="space-title">Effective and efficient adversarial prompt generation approach for diffusion models</h1>"""
29
+
30
+ # What does your leaderboard evaluate?
31
+ INTRODUCTION_TEXT = """
32
+ UnlearnDiffAtk is an effective and efficient adversarial prompt generation approach for unlearned diffusion models(DMs). For more details,
33
+ please refer to the [benchmark of UnlearnDiffAtk](https://huggingface.co/spaces/xinchen9/UnlearnDiffAtk-Benchmark), visit the [project](https://www.optml-group.com/posts/mu_attack),
34
+ check the [code](https://github.com/OPTML-Group/Diffusion-MU-Attack), and read the [paper](https://arxiv.org/abs/2310.11868).\\
35
+ The prompts were validated by us for undesirable concepts: ([Church](https://github.com/OPTML-Group/Diffusion-MU-Attack/blob/e848ddd19df1f86d08e08cc9146f8a2bb126da12/prompts/church.csv),
36
+ [Garbage Truck](https://github.com/OPTML-Group/Diffusion-MU-Attack/blob/e848ddd19df1f86d08e08cc9146f8a2bb126da12/prompts/garbage_truck.csv),
37
+ [Parachute](https://github.com/OPTML-Group/Diffusion-MU-Attack/blob/e848ddd19df1f86d08e08cc9146f8a2bb126da12/prompts/parachute.csv),
38
+ style ([Van Gogh](https://github.com/OPTML-Group/Diffusion-MU-Attack/blob/e848ddd19df1f86d08e08cc9146f8a2bb126da12/prompts/vangogh.csv)),
39
+ and objects ([Nudity](https://github.com/OPTML-Group/Diffusion-MU-Attack/blob/e848ddd19df1f86d08e08cc9146f8a2bb126da12/prompts/nudity.csv)).
40
+
41
+ """
42
+
43
+ # Which evaluations are you running? how can people reproduce what you have?
44
+ LLM_BENCHMARKS_TEXT = f"""
45
+ ## How it works
46
+
47
+ ## Reproducibility
48
+ To reproduce our results, here is the commands you can run:
49
+
50
+ """
51
+
52
+ EVALUATION_QUEUE_TEXT = """
53
+ ## Some good practices before submitting a model
54
+
55
+ ### 1) Make sure you can load your model and tokenizer using AutoClasses:
56
+ ```python
57
+ from transformers import AutoConfig, AutoModel, AutoTokenizer
58
+ config = AutoConfig.from_pretrained("your model name", revision=revision)
59
+ model = AutoModel.from_pretrained("your model name", revision=revision)
60
+ tokenizer = AutoTokenizer.from_pretrained("your model name", revision=revision)
61
+ ```
62
+ If this step fails, follow the error messages to debug your model before submitting it. It's likely your model has been improperly uploaded.
63
+
64
+ Note: make sure your model is public!
65
+ Note: if your model needs `use_remote_code=True`, we do not support this option yet but we are working on adding it, stay posted!
66
+
67
+ ### 2) Convert your model weights to [safetensors](https://huggingface.co/docs/safetensors/index)
68
+ It's a new format for storing weights which is safer and faster to load and use. It will also allow us to add the number of parameters of your model to the `Extended Viewer`!
69
+
70
+ ### 3) Make sure your model has an open license!
71
+ This is a leaderboard for Open LLMs, and we'd love for as many people as possible to know they can use your model πŸ€—
72
+
73
+ ### 4) Fill up your model card
74
+ When we add extra information about models to the leaderboard, it will be automatically taken from the model card
75
+
76
+ ## In case of model failure
77
+ If your model is displayed in the `FAILED` category, its execution stopped.
78
+ Make sure you have followed the above steps first.
79
+ If everything is done, check you can launch the EleutherAIHarness on your model locally, using the above command without modifications (you can add `--limit` to limit the number of examples per task).
80
+ """
81
+
82
+ CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
83
+ CITATION_BUTTON_TEXT = r"""
84
+ @article{zhang2023generate,
85
+ title={To Generate or Not? Safety-Driven Unlearned Diffusion Models Are Still Easy To Generate Unsafe Images... For Now},
86
+ author={Zhang, Yimeng and Jia, Jinghan and Chen, Xin and Chen, Aochuan and Zhang, Yihua and Liu, Jiancheng and Ding, Ke and Liu, Sijia},
87
+ journal={arXiv preprint arXiv:2310.11868},
88
+ year={2023}
89
+ }
90
+ """
app.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import os
4
+ import requests
5
+ import json
6
+ import base64
7
+ from io import BytesIO
8
+ from huggingface_hub import login
9
+ from PIL import Image
10
+
11
+
12
+ # myip = os.environ["0.0.0.0"]
13
+ # myport = os.environ["80"]
14
+ myip = "34.219.98.113"
15
+ myport=8000
16
+
17
+ is_spaces = True if "SPACE_ID" in os.environ else False
18
+
19
+ is_shared_ui = False
20
+
21
+ from css_html_js import custom_css
22
+
23
+ from about import (
24
+ CITATION_BUTTON_LABEL,
25
+ CITATION_BUTTON_TEXT,
26
+ EVALUATION_QUEUE_TEXT,
27
+ INTRODUCTION_TEXT,
28
+ LLM_BENCHMARKS_TEXT,
29
+ TITLE,
30
+ )
31
+
32
+
33
+ def process_image_from_binary(img_stream):
34
+ if img_stream is None:
35
+ print("no image binary")
36
+ return
37
+ image_data = base64.b64decode(img_stream)
38
+ image_bytes = BytesIO(image_data)
39
+ img = Image.open(image_bytes)
40
+
41
+ return img
42
+
43
+ def excute_udiff(diffusion_model_id, concept, steps, attack_id):
44
+ print(f"my IP is {myip}, my port is {myport}")
45
+ print(f"my input is diffusion_model_id: {diffusion_model_id}, concept: {concept}, steps: {steps}")
46
+ response = requests.post('http://{}:{}/udiff'.format(myip, myport),
47
+ json={"diffusion_model_id": diffusion_model_id, "concept": concept, "steps": steps, "attack_id": attack_id},
48
+ timeout=(10, 1200))
49
+ print(f"result: {response}")
50
+ # result = result.text[1:-1]
51
+ prompt1 = ""
52
+ prompt2 = ""
53
+ img1 = None
54
+ img2 = None
55
+ if response.status_code == 200:
56
+ response_json = response.json()
57
+ print(response_json)
58
+ prompt1 = response_json['input_prompt']
59
+ prompt2 = response_json['output_prompt']
60
+ img1 = process_image_from_binary(response_json['no_attack_img'])
61
+ img2 = process_image_from_binary(response_json['attack_img'])
62
+ else:
63
+ print(f"Request failed with status code {response.status_code}")
64
+
65
+ return prompt1, prompt2, img1, img2
66
+
67
+
68
+ css = '''
69
+ .instruction{position: absolute; top: 0;right: 0;margin-top: 0px !important}
70
+ .arrow{position: absolute;top: 0;right: -110px;margin-top: -8px !important}
71
+ #component-4, #component-3, #component-10{min-height: 0}
72
+ .duplicate-button img{margin: 0}
73
+ #img_1, #img_2, #img_3, #img_4{height:15rem}
74
+ #mdStyle{font-size: 0.7rem}
75
+ #titleCenter {text-align:center}
76
+ '''
77
+
78
+
79
+ with gr.Blocks(css=custom_css) as demo:
80
+ gr.HTML(TITLE)
81
+ gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
82
+
83
+ # gr.Markdown("# Demo of UnlearnDiffAtk.")
84
+ # gr.Markdown("### UnlearnDiffAtk is an effective and efficient adversarial prompt generation approach for unlearned diffusion models(DMs).")
85
+ # # gr.Markdown("####For more details, please visit the [project](https://www.optml-group.com/posts/mu_attack),
86
+ # # check the [code](https://github.com/OPTML-Group/Diffusion-MU-Attack), and read the [paper](https://arxiv.org/abs/2310.11868).")
87
+ # gr.Markdown("### Please notice that the process may take a long time, but the results will be saved. You can try it later if it waits for too long.")
88
+
89
+
90
+ with gr.Row() as udiff:
91
+ with gr.Row():
92
+ drop = gr.Dropdown(["Object-Church", "Object-Parachute", "Object-Garbage_Truck","Style-VanGogh",
93
+ "Nudity"],
94
+ label="Unlearning undesirable concepts")
95
+ with gr.Column():
96
+ # gr.Markdown("Please upload your model id.")
97
+ drop_model = gr.Dropdown(["ESD", "FMN", "SPM"],
98
+ label="Unlearned DMs")
99
+ # diffusion_model_T = gr.Textbox(label='diffusion_model_id')
100
+ # concept = gr.Textbox(label='concept')
101
+ # attacker = gr.Textbox(label='attacker')
102
+
103
+ # start_button = gr.Button("Attack!")
104
+ with gr.Column():
105
+ atk_idx = gr.Textbox(label="attack index")
106
+
107
+ with gr.Column():
108
+ shown_columns_step = gr.Slider(
109
+ 0, 100, value=40,
110
+ step=1, label="Attack Steps", info="Choose between 0 and 100",
111
+ interactive=True,)
112
+ with gr.Row() as attack:
113
+ with gr.Column(min_width=512):
114
+ text_input = gr.Textbox(label="Input Prompt")
115
+
116
+ orig_img = gr.Image(label="Image Generated by Input Prompt",width=512,show_share_button=False,show_download_button=False)
117
+ with gr.Column():
118
+ start_button = gr.Button("UnlearnDiffAtk!",size='lg')
119
+ with gr.Column(min_width=512):
120
+ text_ouput = gr.Textbox(label="Prompt Genetated by UnlearnDiffAtk")
121
+ result_img = gr.Image(label="Image Gnerated by Prompt of UnlearnDiffAtk",width=512,show_share_button=False,show_download_button=False)
122
+
123
+
124
+ start_button.click(fn=excute_udiff, inputs=[drop_model, drop, shown_columns_step, atk_idx], outputs=[text_input, text_ouput, orig_img, result_img], api_name="udiff")
125
+
126
+
127
+ demo.queue().launch(server_name='0.0.0.0')
css_html_js.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ custom_css = """
2
+
3
+ .markdown-text {
4
+ font-size: 16px !important;
5
+ }
6
+
7
+ #models-to-add-text {
8
+ font-size: 18px !important;
9
+ }
10
+
11
+ #citation-button span {
12
+ font-size: 16px !important;
13
+ }
14
+
15
+ #citation-button textarea {
16
+ font-size: 16px !important;
17
+ }
18
+
19
+ #citation-button > label > button {
20
+ margin: 6px;
21
+ transform: scale(1.3);
22
+ }
23
+
24
+ #leaderboard-table {
25
+ margin-top: 15px
26
+ }
27
+
28
+ #leaderboard-table-lite {
29
+ margin-top: 15px
30
+ }
31
+
32
+ #search-bar-table-box > div:first-child {
33
+ background: none;
34
+ border: none;
35
+ }
36
+
37
+ #search-bar {
38
+ padding: 0px;
39
+ }
40
+
41
+ /* Limit the width of the first AutoEvalColumn so that names don't expand too much */
42
+ table td:first-child,
43
+ table th:first-child {
44
+ max-width: 400px;
45
+ overflow: auto;
46
+ white-space: nowrap;
47
+ }
48
+
49
+ .tab-buttons button {
50
+ font-size: 20px;
51
+ }
52
+
53
+ #scale-logo {
54
+ border-style: none !important;
55
+ box-shadow: none;
56
+ display: block;
57
+ margin-left: auto;
58
+ margin-right: auto;
59
+ max-width: 600px;
60
+ }
61
+
62
+ #scale-logo .download {
63
+ display: none;
64
+ }
65
+ #filter_type{
66
+ border: 0;
67
+ padding-left: 0;
68
+ padding-top: 0;
69
+ }
70
+ #filter_type label {
71
+ display: flex;
72
+ }
73
+ #filter_type label > span{
74
+ margin-top: var(--spacing-lg);
75
+ margin-right: 0.5em;
76
+ }
77
+ #filter_type label > .wrap{
78
+ width: 103px;
79
+ }
80
+ #filter_type label > .wrap .wrap-inner{
81
+ padding: 2px;
82
+ }
83
+ #filter_type label > .wrap .wrap-inner input{
84
+ width: 1px
85
+ }
86
+ #filter-columns-type{
87
+ border:0;
88
+ padding:0.5;
89
+ }
90
+ #filter-columns-size{
91
+ border:0;
92
+ padding:0.5;
93
+ }
94
+ #box-filter > .form{
95
+ border: 0
96
+ }
97
+ """
98
+
99
+ get_window_url_params = """
100
+ function(url_params) {
101
+ const params = new URLSearchParams(window.location.search);
102
+ url_params = Object.fromEntries(params);
103
+ return url_params;
104
+ }
105
+ """
images/cheetah.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ APScheduler
2
+ black
3
+ click
4
+ datasets
5
+ gradio
6
+ gradio_client
7
+ huggingface-hub>=0.18.0
8
+ matplotlib
9
+ numpy
10
+ pandas
11
+ python-dateutil
12
+ requests
13
+ tqdm
14
+ transformers