File size: 3,697 Bytes
6fef025 f5b8400 6fef025 dd80569 6fef025 f5b8400 6fef025 dd80569 6fef025 dd80569 ecbb4e2 6fef025 dd80569 f5b8400 dd80569 6fef025 f5b8400 ebf1949 ecbb4e2 ebf1949 dd80569 8f8f343 dd80569 ecbb4e2 dd80569 654d3d1 dd80569 ecbb4e2 f5b8400 dd80569 ebf1949 |
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 |
import gradio as gr
from random import randint
from all_models import models
def load_models(model_names):
loaded_models = {}
for model_name in model_names:
try:
model = gr.load(f'models/{model_name}')
except Exception:
model = gr.Interface(lambda txt: "Model load error", inputs=["text"], outputs=["image"])
loaded_models[model_name] = model
return loaded_models
models_load = load_models(models)
num_models = 6
default_models = models[:num_models]
def extend_choices(choices, num_models=6):
return choices + ['NA'] * (num_models - len(choices))
def update_image_boxes(choices):
extended_choices = extend_choices(choices)
return [gr.Image(label=model, visible=(model != 'NA')).style(padding="10px", border_radius="10px", box_shadow="0px 5px 20px rgba(0, 0, 0, 0.1)", transition="transform 0.3s ease-in-out") for model in extended_choices]
def generate_image(model_name, prompt):
if model_name == 'NA':
return None
# If you decide to add randomness to the prompt, uncomment the next line
# prompt += f" {randint(0, 999999999)}"
return models_load[model_name](prompt)
with gr.Blocks() as demo:
with gr.Tab("The Dream").style(padding="20px", border_radius="15px", box_shadow="0px 10px 40px rgba(0, 0, 0, 0.1)", transition="transform 0.3s ease-in-out"):
txt_input = gr.Textbox(label="Your prompt:", lines=4).style(container=False, min_width=1200, border="2px solid #ccc", border_radius="10px", padding="10px", box_shadow="0px 3px 10px rgba(0, 0, 0, 0.1)")
gen_button = gr.Button("Generate up to 6 images").style(background="#4CAF50", color="white", padding="10px 20px", border="none", border_radius="5px", cursor="pointer", transition="background 0.3s ease-in-out")
stop_button = gr.Button("Stop", variant="secondary").style(background="#f44336", color="white", padding="10px 20px", border="none", border_radius="5px", cursor="pointer", transition="background 0.3s ease-in-out")
gen_button.click(lambda _: gr.update(interactive=True), None, stop_button)
with gr.Row():
output_images = [gr.Image(label=model, min_width=480) for model in default_models]
model_textboxes = [gr.Textbox(model, visible=False) for model in default_models]
for model_textbox, output_image in zip(model_textboxes, output_images):
gen_event = gen_button.click(generate_image, [model_textbox, txt_input], output_image)
stop_button.click(lambda _: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
with gr.Accordion("Model selection").style(padding="20px", border_radius="10px", box_shadow="0px 5px 20px rgba(0, 0, 0, 0.1)", transition="transform 0.3s ease-in-out"):
model_choice = gr.CheckboxGroup(choices=models, label=f"Choose up to {num_models} models from the 686 available!", value=default_models, multiselect=True, max_choices=num_models, interactive=True).style(margin="10px 0", padding="10px", border_radius="5px", background="#f9f9f9", box_shadow="0px 3px 10px rgba(0, 0, 0, 0.1)")
model_choice.change(update_image_boxes, model_choice, output_images)
model_choice.change(lambda choices: extend_choices(choices, num_models), model_choice, model_textboxes)
with gr.Row():
gr.HTML("""
<div class="footer">
<p>Based on spaces by derwahnsinn, RdnUser77, and the Omnibus Maximum Multiplier!</p>
</div>
""").style(text_align="center", margin="20px 0")
demo.queue(concurrency_count=200)
demo.launch()
|