Spaces:
Sleeping
Sleeping
Kaixuanliu
commited on
Commit
•
e13c481
1
Parent(s):
62c7d61
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,9 @@ import gradio as gr
|
|
3 |
import os
|
4 |
import requests
|
5 |
import json
|
|
|
6 |
from huggingface_hub import login
|
|
|
7 |
|
8 |
|
9 |
# myip = os.environ["0.0.0.0"]
|
@@ -27,6 +29,13 @@ from about import (
|
|
27 |
)
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def excute_udiff(diffusion_model_id, concept, steps):
|
31 |
print(f"my IP is {myip}, my port is {myport}")
|
32 |
print(f"my input is diffusion_model_id: {diffusion_model_id}, concept: {concept}, steps: {steps}")
|
@@ -35,15 +44,19 @@ def excute_udiff(diffusion_model_id, concept, steps):
|
|
35 |
# result = result.text[1:-1]
|
36 |
prompt1 = ""
|
37 |
prompt2 = ""
|
|
|
|
|
38 |
if response.status_code == 200:
|
39 |
response_json = response.json()
|
40 |
print(response_json)
|
41 |
prompt1 = response_json['input_prompt']
|
42 |
prompt2 = response_json['output_prompt']
|
|
|
|
|
43 |
else:
|
44 |
print(f"Request failed with status code {response.status_code}")
|
45 |
|
46 |
-
return prompt1, prompt2
|
47 |
|
48 |
|
49 |
css = '''
|
@@ -91,15 +104,16 @@ with gr.Blocks(css=custom_css) as demo:
|
|
91 |
with gr.Row() as attack:
|
92 |
with gr.Column(min_width=260):
|
93 |
text_input = gr.Textbox(label="Input Prompt")
|
94 |
-
|
|
|
95 |
with gr.Column():
|
96 |
start_button = gr.Button("UnlearnDiffAtk!",size='lg')
|
97 |
with gr.Column(min_width=260):
|
98 |
text_ouput = gr.Textbox(label="Prompt Genetated by UnlearnDiffAtk")
|
99 |
-
img2 = gr.Image(
|
100 |
|
101 |
|
102 |
-
start_button.click(fn=excute_udiff, inputs=[drop_model, drop, shown_columns_step], outputs=[text_input, text_ouput], api_name="udiff")
|
103 |
|
104 |
|
105 |
demo.queue().launch(server_name='0.0.0.0')
|
|
|
3 |
import os
|
4 |
import requests
|
5 |
import json
|
6 |
+
import base64
|
7 |
from huggingface_hub import login
|
8 |
+
import Image
|
9 |
|
10 |
|
11 |
# myip = os.environ["0.0.0.0"]
|
|
|
29 |
)
|
30 |
|
31 |
|
32 |
+
def process_image_from_binary(img_stream):
|
33 |
+
image_data = base64.b64decode(img_stream)
|
34 |
+
image_bytes = BytesIO(image_data)
|
35 |
+
img = Image.open(image_bytes)
|
36 |
+
|
37 |
+
return img
|
38 |
+
|
39 |
def excute_udiff(diffusion_model_id, concept, steps):
|
40 |
print(f"my IP is {myip}, my port is {myport}")
|
41 |
print(f"my input is diffusion_model_id: {diffusion_model_id}, concept: {concept}, steps: {steps}")
|
|
|
44 |
# result = result.text[1:-1]
|
45 |
prompt1 = ""
|
46 |
prompt2 = ""
|
47 |
+
img1 = None
|
48 |
+
img2 = None
|
49 |
if response.status_code == 200:
|
50 |
response_json = response.json()
|
51 |
print(response_json)
|
52 |
prompt1 = response_json['input_prompt']
|
53 |
prompt2 = response_json['output_prompt']
|
54 |
+
img1 = process_image_from_binary(response_json['no_attack_img'])
|
55 |
+
img2 = process_image_from_binary(response_json['attack_img'])
|
56 |
else:
|
57 |
print(f"Request failed with status code {response.status_code}")
|
58 |
|
59 |
+
return prompt1, prompt2, img1, img2
|
60 |
|
61 |
|
62 |
css = '''
|
|
|
104 |
with gr.Row() as attack:
|
105 |
with gr.Column(min_width=260):
|
106 |
text_input = gr.Textbox(label="Input Prompt")
|
107 |
+
|
108 |
+
img1 = gr.Image(orig_img,label="Image Generated by Input Prompt",width=260,show_share_button=False,show_download_button=False)
|
109 |
with gr.Column():
|
110 |
start_button = gr.Button("UnlearnDiffAtk!",size='lg')
|
111 |
with gr.Column(min_width=260):
|
112 |
text_ouput = gr.Textbox(label="Prompt Genetated by UnlearnDiffAtk")
|
113 |
+
img2 = gr.Image(result_img,label="Image Gnerated by Prompt of UnlearnDiffAtk",width=260,show_share_button=False,show_download_button=False)
|
114 |
|
115 |
|
116 |
+
start_button.click(fn=excute_udiff, inputs=[drop_model, drop, shown_columns_step], outputs=[text_input, text_ouput, orig_img, result_img], api_name="udiff")
|
117 |
|
118 |
|
119 |
demo.queue().launch(server_name='0.0.0.0')
|