File size: 7,418 Bytes
d49243a
 
2de36a8
39aef48
 
 
 
 
 
 
 
 
0b74261
39aef48
 
 
 
 
 
 
 
2de36a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dff5884
2de36a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39aef48
2de36a8
 
 
 
 
 
 
39aef48
2de36a8
 
 
 
 
 
39aef48
 
231b559
 
dc08a66
 
 
 
 
 
2de36a8
 
 
 
 
 
39aef48
 
2de36a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1a4a2a
2de36a8
 
 
6c307e5
39aef48
2de36a8
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import gradio as gr
import numpy as np
from methods import infer

model_id_default = "sd-legacy/stable-diffusion-v1-5"
model_dropdown = ['stabilityai/sdxl-turbo', 'CompVis/stable-diffusion-v1-4', 'sd-legacy/stable-diffusion-v1-5']

MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 1024


examples = [
    "Cartoon sticker of sad Elon Musk",
    "A cartoon-style sticker of Elon Musk shaking hands with Donald Trump. Both figures have exaggerated facial expressions, with Musk grinning confidently and Trump giving a signature thumbs-up. The background features a patriotic red, white, and blue color scheme with fireworks exploding behind them.",
    "A cyberpunk-themed cartoon sticker of Elon Musk standing atop a futuristic Tesla spaceship. He wears a sleek, neon-lit jacket with glowing circuits, while the city skyline behind him is filled with holographic billboards displaying SpaceX and Neuralink logos. His sunglasses reflect the distant stars, adding to the sci-fi aesthetic.",
    "A medieval fantasy sticker of Elon Musk depicted as a wizard. He holds a glowing blue orb in one hand and a spellbook in the other, wearing a long, starry robe with intricate golden details. His expression is both wise and mischievous, as if he's about to reveal the secrets of the universe. The background features a mystical castle and a dragon flying in the sky.",
    "A sticker of Elon Musk dressed as a cowboy in the Wild West. He wears a wide-brimmed hat, leather boots, and a long trench coat, standing in front of a saloon with a SpaceX rocket docked nearby instead of a horse. A wanted poster on the wall reads 'Wanted: Mars Pioneer', adding to the playful western theme.",
    "A parody cartoon sticker of Elon Musk arm-wrestling a robotic version of himself. The robot Musk has glowing red eyes and mechanical arms, while the real Musk smirks confidently. Sparks fly from the table as the intense match unfolds, and the background features a neon sign that reads 'Tesla vs. AI: Ultimate Showdown'."
]


def on_checkbox_change(use_advanced):
    visible = use_advanced
    return (gr.update(visible=visible, interactive=visible),
            gr.update(visible=visible, interactive=visible),
            gr.update(visible=visible, interactive=visible))


with gr.Blocks() as demo:
    with gr.Row():

        with gr.Column(): 

            gr.Markdown("## ControlNet")
            use_advanced_controlnet = gr.Checkbox(label="ControlNet Settings")
            control_strength = gr.Slider(
                    label="control_strength",
                    minimum=0,
                    maximum=1,
                    step=0.01,
                    value=0.8,
                    visible=False)
            mode = gr.Dropdown(["edge_detection", "pose_estimation"], label="Выбор режима", visible=False)
            image_upload_cn = gr.Image(label="Загрузите изображение", visible=False)
            use_advanced_controlnet.change(on_checkbox_change, use_advanced_controlnet, [control_strength, mode, image_upload_cn])

            gr.Markdown("## IPAdapter")
            use_advanced_ip = gr.Checkbox(label="IPAdapter Settings")
            ip_adapter_scale = gr.Slider(
                    label="ip_adapter_scale",
                    minimum=0,
                    maximum=1,
                    step=0.01,
                    value=0.8,
                    visible=False)
            image_upload_ip = gr.Image(label="Загрузите изображение", visible=False)
            use_advanced_ip.change(on_checkbox_change, use_advanced_ip, [ip_adapter_scale, image_upload_ip])


        with gr.Column(): 
            gr.Markdown("## Generate")

            with gr.Row():
                prompt = gr.Text(
                    label="Prompt",
                    show_label=False,
                    max_lines=1,
                    placeholder="Enter your prompt",
                    container=False,
                    )
                run_button = gr.Button("Run", scale=0, variant="primary")

            result = gr.Image(label="Result", show_label=False)

            with gr.Accordion("Advanced Settings", open=False):
                
                model_repo_id = gr.Dropdown(
                    label="Model Id",
                    choices=model_dropdown,
                    info="Choose model",
                    visible=True,
                    allow_custom_value=True,
                    value=model_id_default,
                )  

                negative_prompt = gr.Text(
                    label="Negative prompt",
                    max_lines=1,
                    placeholder="Enter a negative prompt",
                    visible=True,
                    value="monochrome, lowres, bad anatomy, worst quality, low quality, medical mask"
                )

                seed = gr.Slider(
                    label="Seed",
                    minimum=0,
                    maximum=MAX_SEED,
                    step=1,
                    value=22,
                )

                guidance_scale = gr.Slider(
                    label="guidance_scale",
                    minimum=0,
                    maximum=100,
                    step=1,
                    value=7,
                )

                lora_scale = gr.Slider(
                    label="lora_scale",
                    minimum=0,
                    maximum=1,
                    step=0.01,
                    value=0.95,
                    visible=False)

                num_inference_steps = gr.Slider(
                    label="num_inference_steps",
                    minimum=0,
                    maximum=100,
                    step=1,
                    value=50,
                )

                randomize_seed = gr.Checkbox(label="Randomize seed", value=True)

                with gr.Row():   
                    width = gr.Slider(
                        label="Width",
                        minimum=256,
                        maximum=MAX_IMAGE_SIZE,
                        step=32,
                        value=512,  # Replace with defaults that work for your model
                    )

                    height = gr.Slider(
                        label="Height",
                        minimum=256,
                        maximum=MAX_IMAGE_SIZE,
                        step=32,
                        value=512,  # Replace with defaults that work for your model
                    )

            with gr.Accordion("Prompt examples", open=False):
                gr.Examples(examples=examples, inputs=[prompt])

            gr.on(
                triggers=[run_button.click, prompt.submit],
                fn=infer,
                inputs=[
                    prompt,
                    negative_prompt,
                    randomize_seed,
                    width,
                    height,
                    model_repo_id,
                    seed, 
                    guidance_scale,
                    num_inference_steps,

                    use_advanced_controlnet,
                    control_strength,
                    image_upload_cn,

                    use_advanced_ip,
                    ip_adapter_scale,
                    image_upload_ip
                ],
                outputs=[result, seed],
            )

if __name__ == "__main__":
    demo.launch(share=False, debug=True)