File size: 2,249 Bytes
fa03427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bc6845
fa03427
2bc6845
 
e03adb5
fa03427
010d641
fa03427
 
 
 
 
 
 
 
 
 
 
 
 
 
ceb9f04
 
 
fa03427
 
 
 
2bc6845
fa03427
 
 
 
 
2793457
010d641
ee55c3a
 
2793457
c7a8c4e
2bc6845
2793457
2bc6845
fa03427
 
 
fb2570f
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import gradio as gr
import os
import requests
import json
from huggingface_hub import login


myip = os.environ["myip"]
myport = os.environ["myport"]


is_spaces = True if "SPACE_ID" in os.environ else False

is_shared_ui = False


def excute_udiff(diffusion_model_id, concept, attacker):
    print(f"my IP is {myip}, my port is {myport}")
    print(f"my input is diffusion_model_id: {diffusion_model_id}, concept: {concept}, attacker: {attacker}")
    result = requests.post('http://{}:{}/udiff'.format(myip, myport), json={"diffusion_model_id": diffusion_model_id, "concept": concept, "attacker": attacker})
    result = result.text[1:-1]
    
    return result


css = '''
    .instruction{position: absolute; top: 0;right: 0;margin-top: 0px !important}
    .arrow{position: absolute;top: 0;right: -110px;margin-top: -8px !important}
    #component-4, #component-3, #component-10{min-height: 0}
    .duplicate-button img{margin: 0}
    #img_1, #img_2, #img_3, #img_4{height:15rem}
    #mdStyle{font-size: 0.7rem}
    #titleCenter {text-align:center}
'''


with gr.Blocks(css=css) as demo:
    gr.Markdown("# Unlearn Diffusions Attack")
    gr.Markdown("### It will generate a prompt to lead your model output unsafe image.")
    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.")

    with gr.Row() as udiff:
        with gr.Column():
            # gr.Markdown("Please upload your model id.")
            diffusion_model_id = gr.Textbox(label='diffusion_model_id')
            concept = gr.Textbox(label='concept')
            attacker = gr.Textbox(label='attacker')

            start_button = gr.Button("Attack!")

        with gr.Column():
            result = gr.Textbox(label="unsafe prompt")

    with gr.Column():
        gr.Examples(examples=[
            ["CompVis/stable-diffusion-v1-4", "nudity", "text_grad"]
        ], inputs=[diffusion_model_id, concept, attacker])

    start_button.click(fn=excute_udiff, inputs=[diffusion_model_id, concept, attacker], outputs=result, api_name="udiff")


# demo.queue(default_enabled=False, api_open=False, max_size=5).launch(debug=True, show_api=False)
demo.queue().launch(server_name='0.0.0.0')