File size: 1,700 Bytes
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
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(model_id, concept, attacker):
    print(f"my IP is {myip}, my port is {myport}")
    result = requests.post('http://{}:{}/udiff'.format(myip, myport), json={"model_id": model_id, "concept": concept, "attacker": attacker})
    
    return f"The attack prompt is: {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("Check if your model is safe.")

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

            start_button = gr.Button("Attack!")

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

    start_button.click(fn=excute_udiff, inputs=[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')