Spaces:
Sleeping
Sleeping
File size: 2,348 Bytes
222d7ce 23d59a5 566b9eb e7e8aa5 222d7ce c50d086 d1adaa8 23d59a5 e7e8aa5 1d193c7 566b9eb 41f1c59 1d193c7 566b9eb e7e8aa5 deba054 41f1c59 c50d086 e7e8aa5 222d7ce |
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 65 66 67 68 69 70 71 |
import gradio as gr
import os
import requests
import json
from huggingface_hub import login
from css_html_js import custom_css
from about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
EVALUATION_QUEUE_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT,
TITLE,
)
myip = "34.219.98.113"
myport=80
is_spaces = True if "SPACE_ID" in os.environ else False
is_shared_ui = False
def process_image_from_binary(img_stream):
if img_stream is None:
print("no image binary")
return
image_data = base64.b64decode(img_stream)
image_bytes = BytesIO(image_data)
img = Image.open(image_bytes)
return img
def generate_img(concept, prompt):
print(f"my IP is {myip}, my port is {myport}")
print(f"my input is diffusion_model_id: {diffusion_model_id}, concept: {concept}, steps: {steps}")
response = requests.post('http://{}:{}/generate'.format(myip, myport),
json={"concept": concept, "prompt": prompt},
timeout=(10, 1200))
print(f"result: {response}")
image = None
if response.status_code == 200:
response_json = response.json()
print(response_json)
image = process_image_from_binary(response_json[‘img'])
else:
print(f"Request failed with status code {response.status_code}")
return image
with gr.Blocks() as demo:
gr.HTML(TITLE)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Row() as advlearn:
with gr.Column():
# gr.Markdown("Please upload your model id.")
drop_text = gr.Dropdown(["Object-Church", "Object-Parachute", "Object-Garbage_Truck",
"Style-Van_Gogh","Concept-Nudity", "None"],
label="AdvUnlearn Text Encoder")
with gr.Column():
text_input = gr.Textbox(label="Prompt")
with gr.Row():
with gr.Column():
start_button = gr.Button("AdvUnlearn",size='lg')
with gr.Column(min_width=512):
result_img = gr.Image(label="Image Gnerated by AdvUnlearn",width=512,show_share_button=False,show_download_button=False)
start_button.click(fn=generate_img, inputs=[drop_text, text_input], outputs=result_img, api_name="generate")
demo.launch() |