Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import av
|
| 4 |
+
import base64
|
| 5 |
+
import cv2
|
| 6 |
+
import torch
|
| 7 |
+
import time
|
| 8 |
+
import numpy as np
|
| 9 |
+
import requests
|
| 10 |
+
import json
|
| 11 |
+
from huggingface_hub import login
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
myip = os.environ["myip"]
|
| 15 |
+
myport = os.environ["myport"]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
is_spaces = True if "SPACE_ID" in os.environ else False
|
| 19 |
+
|
| 20 |
+
is_shared_ui = False
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def excute_udiff(model_id, concept, attacker):
|
| 24 |
+
print(f"my IP is {myip}, my port is {myport}")
|
| 25 |
+
result = requests.post('http://{}:{}/udiff'.format(myip, myport), json={"model_id": model_id, "concept": concept, "attacker": attacker})
|
| 26 |
+
|
| 27 |
+
return f"The attack prompt is: {result}"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
css = '''
|
| 31 |
+
.instruction{position: absolute; top: 0;right: 0;margin-top: 0px !important}
|
| 32 |
+
.arrow{position: absolute;top: 0;right: -110px;margin-top: -8px !important}
|
| 33 |
+
#component-4, #component-3, #component-10{min-height: 0}
|
| 34 |
+
.duplicate-button img{margin: 0}
|
| 35 |
+
#img_1, #img_2, #img_3, #img_4{height:15rem}
|
| 36 |
+
#mdStyle{font-size: 0.7rem}
|
| 37 |
+
#titleCenter {text-align:center}
|
| 38 |
+
'''
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
with gr.Blocks(css=css) as demo:
|
| 42 |
+
gr.Markdown("## Unlearn Diffusions Attack")
|
| 43 |
+
gr.Markdown("Check if your model is safe.")
|
| 44 |
+
|
| 45 |
+
with gr.Row() as udiff:
|
| 46 |
+
with gr.Column():
|
| 47 |
+
# gr.Markdown("Please upload your model id.")
|
| 48 |
+
model_id = gr.Textbox(label='model_id')
|
| 49 |
+
concept = gr.Textbox(label='concept')
|
| 50 |
+
attacker = gr.Textbox(label='attacker')
|
| 51 |
+
|
| 52 |
+
start_button = gr.Button("Attack!")
|
| 53 |
+
|
| 54 |
+
with gr.Column():
|
| 55 |
+
result = gr.Textbox(label="attack prompt")
|
| 56 |
+
|
| 57 |
+
start_button.click(fn=excute_udiff, inputs=[model_id, concept, attacker], outputs=result, api_name="udiff")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# demo.queue(default_enabled=False, api_open=False, max_size=5).launch(debug=True, show_api=False)
|
| 61 |
+
demo.queue(concurrency_count=5).launch(debug=True, server_name='0.0.0.0')
|