Spaces:
Sleeping
Sleeping
Kaixuanliu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,33 @@ is_spaces = True if "SPACE_ID" in os.environ else False
|
|
21 |
is_shared_ui = False
|
22 |
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
with gr.Blocks() as demo:
|
25 |
gr.HTML(TITLE)
|
26 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
@@ -37,6 +64,8 @@ with gr.Blocks() as demo:
|
|
37 |
with gr.Column():
|
38 |
start_button = gr.Button("AdvUnlearn",size='lg')
|
39 |
with gr.Column(min_width=512):
|
40 |
-
|
|
|
|
|
41 |
|
42 |
demo.launch()
|
|
|
21 |
is_shared_ui = False
|
22 |
|
23 |
|
24 |
+
def process_image_from_binary(img_stream):
|
25 |
+
if img_stream is None:
|
26 |
+
print("no image binary")
|
27 |
+
return
|
28 |
+
image_data = base64.b64decode(img_stream)
|
29 |
+
image_bytes = BytesIO(image_data)
|
30 |
+
img = Image.open(image_bytes)
|
31 |
+
|
32 |
+
return img
|
33 |
+
|
34 |
+
def generate_img(concept, prompt):
|
35 |
+
print(f"my IP is {myip}, my port is {myport}")
|
36 |
+
print(f"my input is diffusion_model_id: {diffusion_model_id}, concept: {concept}, steps: {steps}")
|
37 |
+
response = requests.post('http://{}:{}/generate'.format(myip, myport),
|
38 |
+
json={"concept": concept, "prompt": prompt},
|
39 |
+
timeout=(10, 1200))
|
40 |
+
print(f"result: {response}")
|
41 |
+
image = None
|
42 |
+
if response.status_code == 200:
|
43 |
+
response_json = response.json()
|
44 |
+
print(response_json)
|
45 |
+
image = process_image_from_binary(response_json[‘img'])
|
46 |
+
else:
|
47 |
+
print(f"Request failed with status code {response.status_code}")
|
48 |
+
|
49 |
+
return image
|
50 |
+
|
51 |
with gr.Blocks() as demo:
|
52 |
gr.HTML(TITLE)
|
53 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
|
|
64 |
with gr.Column():
|
65 |
start_button = gr.Button("AdvUnlearn",size='lg')
|
66 |
with gr.Column(min_width=512):
|
67 |
+
result_img = gr.Image(label="Image Gnerated by AdvUnlearn",width=512,show_share_button=False,show_download_button=False)
|
68 |
+
|
69 |
+
start_button.click(fn=generate_img, inputs=[drop_text, text_input], outputs=result_img, api_name="generate")
|
70 |
|
71 |
demo.launch()
|