File size: 9,232 Bytes
674ff96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import gradio as gr
# import os
# import sys
# from pathlib import Path
import time

models =[
    "John6666/ultimate-realistic-mix-v2-sdxl",
    "SG161222/RealVisXL_V3.0_Turbo",
    "Yntec/DegreesOfFreedom",
    "Yntec/UltraHighDefinition",
    "John6666/9527-detail-realistic-xl-v55mix-sdxl",
    "mann-e/Mann-E_Dreams",
    "John6666/wai-real-mix-v8-sdxl",
    "John6666/real-vis-xl-v40-sdxl",
    "Yntec/BeautyFoolRemix",
]

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):

    text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
    return prompt_text

def clear_it(val):
    if int(val) != 0:
        val = 0
    else:
        val = 0
        pass
    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)
        #print(f'to: {to}  et: {et}')
    else:
        if cnt != 0:
            d = gr.update(value=et)
        else:
            d = gr.update(value=0)
        tog = gr.update(value=0)
        #print (f'passing:  to: {to}  et: {et}')
        pass
    return d, tog

def all_task_start():
    print("\n\n\n\n\n\n\n")
    t = time.gmtime()
    t_stamp = time.time()
    current_time = time.strftime("%H:%M:%S", t)
    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)]])



with gr.Blocks(title="SD Models") as my_interface:
    with gr.Column(scale=12):
        # with gr.Row():
        #     gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
        with gr.Row():
            with gr.Row(scale=6):
                primary_prompt=gr.Textbox(label="Prompt", value="")
                # real_prompt=gr.Textbox(label="Real prompt")
            with gr.Row(scale=6):
                # improve_prompts_btn=gr.Button("Improve")
                with gr.Row():
                    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)
                    pass
                model_idx += 1
                pass
            pass

        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
            pass
        pass
import gradio as gr
# import os
# import sys
# from pathlib import Path
import time

models =[
    "John6666/ultimate-realistic-mix-v2-sdxl",
    "SG161222/RealVisXL_V3.0_Turbo",
    "Yntec/DegreesOfFreedom",
    "Yntec/UltraHighDefinition",
    "John6666/9527-detail-realistic-xl-v55mix-sdxl",
    "mann-e/Mann-E_Dreams",
    "John6666/wai-real-mix-v8-sdxl",
    "John6666/real-vis-xl-v40-sdxl",
    "Yntec/BeautyFoolRemix",
]

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):

    text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
    return prompt_text

def clear_it(val):
    if int(val) != 0:
        val = 0
    else:
        val = 0
        pass
    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)
        #print(f'to: {to}  et: {et}')
    else:
        if cnt != 0:
            d = gr.update(value=et)
        else:
            d = gr.update(value=0)
        tog = gr.update(value=0)
        #print (f'passing:  to: {to}  et: {et}')
        pass
    return d, tog

def all_task_start():
    print("\n\n\n\n\n\n\n")
    t = time.gmtime()
    t_stamp = time.time()
    current_time = time.strftime("%H:%M:%S", t)
    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)]])



with gr.Blocks(title="SD Models") as my_interface:
    with gr.Column(scale=12):
        # with gr.Row():
        #     gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
        with gr.Row():
            with gr.Row(scale=6):
                primary_prompt=gr.Textbox(label="Prompt", value="")
                # real_prompt=gr.Textbox(label="Real prompt")
            with gr.Row(scale=6):
                # improve_prompts_btn=gr.Button("Improve")
                with gr.Row():
                    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)
                    pass
                model_idx += 1
                pass
            pass

        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
            pass
        text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")

        # improve_prompts_btn_clicked=improve_prompts_btn.click(
        #     get_prompts,
        #     inputs=[primary_prompt],
        #     outputs=[primary_prompt],
        #     cancels=list(runs_dict.values()))
        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())])

my_interface.queue(concurrency_count=600, status_update_rate=1)


        # improve_prompts_btn_clicked=improve_prompts_btn.click(
        #     get_prompts,
        #     inputs=[primary_prompt],
        #     outputs=[primary_prompt],
        #     cancels=list(runs_dict.values()))
        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())])

my_interface.queue(concurrency_count=600, status_update_rate=1)