|
import gradio as gr |
|
import time |
|
|
|
models = [ |
|
"mann-e/Mann-E_Dreams", |
|
"Yntec/ChickFlick", |
|
"John6666/ultimate-realistic-mix-v2-sdxl", |
|
"Yntec/CrystalReality", |
|
"John6666/9527-detail-realistic-xl-v55mix-sdxl", |
|
"John6666/epicrealism-xl-v8kiss-sdxl", |
|
"John6666/wai-real-mix-v8-sdxl", |
|
"John6666/real-vis-xl-v40-sdxl", |
|
"Yntec/DegreesOfFreedom", |
|
] |
|
|
|
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(idx) or model_functions.get(1))(prompt) |
|
return output |
|
return send_it_fn |
|
|
|
def get_prompts(prompt_text): |
|
return prompt_text |
|
|
|
def clear_it(val): |
|
return 0 |
|
|
|
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: |
|
d = gr.update(value=et) if cnt != 0 else gr.update(value=0) |
|
tog = gr.update(value=0) |
|
return d, tog |
|
|
|
def all_task_start(): |
|
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 (None, *[None for _ in range(nn)]) |
|
|
|
with gr.Blocks(title="SD Models") as my_interface: |
|
with gr.Column(scale=12): |
|
with gr.Row(): |
|
with gr.Column(scale=6): |
|
primary_prompt = gr.Textbox(label="Prompt", value="") |
|
with gr.Column(scale=6): |
|
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( |
|
send_it_idx(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())] |
|
) |
|
|
|
text_gen1 = gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion") |
|
|
|
my_interface.queue(concurrency_count=600, status_update_rate=1) |
|
my_interface.launch(inline=True, show_api=True) |
|
|