File size: 2,570 Bytes
222d7ce
23d59a5
 
 
165dc5d
70ab081
e16e2d6
23d59a5
 
 
 
 
 
 
 
 
 
 
 
 
566b9eb
83a1864
e7e8aa5
 
 
222d7ce
c50d086
 
 
 
 
 
 
 
 
 
81351b9
c50d086
 
81351b9
c50d086
 
 
 
 
 
e75ddc5
c50d086
 
 
 
 
d1adaa8
23d59a5
 
e7e8aa5
1d193c7
566b9eb
41f1c59
2ba6b16
1d193c7
566b9eb
 
e7e8aa5
deba054
 
d7d4715
 
 
 
f552bec
d7d4715
41f1c59
c50d086
 
81351b9
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
72
73
74
75
76
77
78
import gradio as gr
import os
import requests
import json
import base64
from io import BytesIO
from PIL import Image
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=8080
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, seed, steps):
    print(f"my IP is {myip}, my port is {myport}")
    response = requests.post('http://{}:{}/generate'.format(myip, myport), 
                             json={"concept": concept, "prompt": prompt, "seed": seed, "steps": steps},
                             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['image'])
    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-VanGogh","Concept-Nudity", "None"], 
                                   label="AdvUnlearn Text Encoder")
        with gr.Column():
            text_input = gr.Textbox(label="Prompt")
        
    with gr.Row():
        with gr.Column():
            with gr.Row():
                seed = gr.Textbox(label="seed", value=666)
            with gr.Row():
                steps = gr.Textbox(label="num_steps", value=100)
            with gr.Row():
                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, seed, steps], outputs=result_img, api_name="generate")
            
demo.launch()