File size: 3,557 Bytes
063b292
47ce067
063b292
 
47ce067
f5e64be
0bb5a0b
 
063b292
 
 
 
88ba3ca
063b292
 
 
88ba3ca
47ce067
063b292
 
 
88ba3ca
 
063b292
 
 
 
 
 
88ba3ca
 
 
 
 
063b292
47ce067
063b292
 
 
 
 
 
88ba3ca
 
 
 
063b292
 
 
 
88ba3ca
063b292
 
 
88ba3ca
063b292
88ba3ca
063b292
47ce067
 
 
 
 
 
 
fe9f7af
6d17160
88ba3ca
 
8796d5d
 
 
88ba3ca
 
 
 
 
 
 
 
 
 
47ce067
 
 
88ba3ca
 
 
 
 
 
47ce067
 
88ba3ca
 
 
47ce067
88ba3ca
 
 
 
 
47ce067
88ba3ca
 
 
 
47ce067
 
88ba3ca
 
 
 
47ce067
 
 
 
 
1d44b13
88ba3ca
 
47ce067
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
import gradio as gr
import random
import time

models = [
    "John6666/ultimate-realistic-mix-v2-sdxl",
]

model_functions = {}
model_idx = 1
for model_path in models:
    try:
        model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
    except Exception as error:
        def the_fn(txt):
            return None
        model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
    model_idx += 1

def send_it_idx(idx):
    def send_it_fn(prompt):
        output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
        return output
    return send_it_fn

def get_prompts(prompt_text):
    return prompt_text

def clear_it(val):
    if int(val) != 0:
        val = 0
    else:
        val = 0
    return val

def all_task_end(cnt, t_stamp):
    to = t_stamp + 360
    et = time.time()
    if et > to and t_stamp != 0:
        d = gr.update(value=0)
        tog = gr.update(value=1)
    else:
        if cnt != 0:
            d = gr.update(value=et)
        else:
            d = gr.update(value=0)
        tog = gr.update(value=0)
    return d, tog

def all_task_start():
    t = time.gmtime()
    t_stamp = time.time()
    return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)

def clear_fn():
    nn = len(models)
    return tuple([None, *[None for _ in range(nn)]])

def generate_random_images():
    prompt = "Random seed image"
    outputs = []
    for _ in range(3):
        output = model_functions[1](prompt)
        outputs.append(output)
    return outputs

with gr.Blocks(title="SD Models") as my_interface:
    with gr.Column(scale=12):
        with gr.Row():
            primary_prompt = gr.Textbox(label="Prompt", value="")
            run = gr.Button("Run", variant="primary")
            clear_btn = gr.Button("Clear")
        with gr.Row():
            sd_outputs = {}
            model_idx = 1
            for model_path in models:
                with gr.Column(scale=3, min_width=320):
                    with gr.Box():
                        sd_outputs[model_idx] = gr.Image(label=model_path)
                model_idx += 1

        with gr.Row(visible=False):
            start_box = gr.Number(interactive=False)
            end_box = gr.Number(interactive=False)
            tog_box = gr.Textbox(value=0, interactive=False)

        start_box.change(
            all_task_end,
            [start_box, end_box],
            [start_box, tog_box],
            every=1,
            show_progress=True
        )

        primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
        run.click(all_task_start, None, [start_box, end_box, tog_box])

        runs_dict = {}
        model_idx = 1
        for model_path in models:
            runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
            model_idx += 1

        clear_btn.click(
            clear_fn,
            None,
            [primary_prompt, *list(sd_outputs.values())],
            cancels=[*list(runs_dict.values())]
        )
        tog_box.change(
            clear_it,
            tog_box,
            tog_box,
            cancels=[*list(runs_dict.values())]
        )

        random_images = generate_random_images()
        for i, img in enumerate(random_images):
            sd_outputs[i+1].value = img

my_interface.queue(concurrency_count=600, status_update_rate=1)
my_interface.launch(inline=True, show_api=True)