Spaces:
Runtime error
Runtime error
jordonpeter01
commited on
Commit
•
3f65faf
1
Parent(s):
17abe49
Update app.py
Browse files
app.py
CHANGED
@@ -2,54 +2,60 @@ import gradio as gr
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
global models_load
|
9 |
-
models_load = {}
|
10 |
-
|
11 |
for model in models:
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
num_models = 150
|
24 |
default_models = models[:num_models]
|
25 |
|
26 |
-
|
27 |
-
|
28 |
def extend_choices(choices):
|
29 |
-
return choices + (num_models - len(choices))
|
30 |
|
31 |
-
|
32 |
-
def update_imgbox(choices):
|
33 |
choices_plus = extend_choices(choices)
|
34 |
-
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
def
|
38 |
if model_str == 'NA':
|
39 |
return None
|
40 |
-
noise = str(
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
44 |
|
|
|
45 |
with gr.Blocks() as demo:
|
46 |
-
with gr.Tab('The Dream'):
|
47 |
-
txt_input = gr.Textbox(label
|
|
|
48 |
gen_button = gr.Button('Generate up to 150 images in up to 3 minutes total')
|
49 |
-
stop_button = gr.Button('Stop', variant
|
50 |
-
|
|
|
|
|
|
|
51 |
gr.HTML(
|
52 |
-
|
53 |
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
54 |
<div>
|
55 |
<body>
|
@@ -58,27 +64,42 @@ with gr.Blocks() as demo:
|
|
58 |
</body>
|
59 |
</div>
|
60 |
</div>
|
61 |
-
|
62 |
-
|
|
|
63 |
with gr.Row():
|
64 |
-
output = [gr.Image(label
|
65 |
-
current_models = [gr.Textbox(m, visible
|
66 |
-
|
67 |
for m, o in zip(current_models, output):
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
70 |
with gr.Accordion('Model selection'):
|
71 |
-
model_choice = gr.CheckboxGroup(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
model_choice.change(update_imgbox, model_choice, output)
|
73 |
model_choice.change(extend_choices, model_choice, current_models)
|
|
|
74 |
with gr.Row():
|
75 |
gr.HTML(
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
)
|
82 |
-
|
83 |
-
demo.queue(concurrency_count
|
84 |
-
demo.launch()
|
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
|
5 |
+
# Função para carregar os modelos e armazená-los em um dicionário
|
6 |
+
def load_models(models):
|
7 |
+
models_dict = {}
|
|
|
|
|
|
|
8 |
for model in models:
|
9 |
+
try:
|
10 |
+
# Tente carregar o modelo e armazená-lo no dicionário
|
11 |
+
model_obj = gr.load(f'models/{model}')
|
12 |
+
models_dict[model] = model_obj
|
13 |
+
except Exception as e:
|
14 |
+
# Lidar com exceções ao carregar o modelo
|
15 |
+
print(f"Erro ao carregar o modelo {model}: {e}")
|
16 |
+
models_dict[model] = gr.Interface(lambda txt: None, ['text'], ['image'])
|
17 |
+
return models_dict
|
18 |
+
|
19 |
+
# Carregar os modelos e armazená-los na variável global
|
20 |
+
models_load = load_models(models)
|
21 |
|
22 |
num_models = 150
|
23 |
default_models = models[:num_models]
|
24 |
|
25 |
+
# Função para estender as escolhas com 'NA' se necessário
|
|
|
26 |
def extend_choices(choices):
|
27 |
+
return choices + ['NA'] * (num_models - len(choices))
|
28 |
|
29 |
+
# Função para atualizar a caixa de imagens com base nas escolhas
|
30 |
+
def update_imgbox(choices, output):
|
31 |
choices_plus = extend_choices(choices)
|
32 |
+
for m, o in zip(choices_plus, output):
|
33 |
+
o.label = m
|
34 |
+
o.visible = (m != 'NA')
|
35 |
|
36 |
+
# Função para gerar imagens com base no modelo e prompt selecionados
|
37 |
+
def generate_images(model_str, prompt, negative_prompt):
|
38 |
if model_str == 'NA':
|
39 |
return None
|
40 |
+
noise = str(randint(0, 99999999999))
|
41 |
+
prompt_with_noise = f'{prompt} {noise}'
|
42 |
+
if negative_prompt:
|
43 |
+
prompt_with_noise += ' Negative'
|
44 |
+
return models_load[model_str](prompt_with_noise)
|
45 |
|
46 |
+
# Interface Gradio
|
47 |
with gr.Blocks() as demo:
|
48 |
+
with gr.Tab('The Dream'):
|
49 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=4).style(container=False, min_width=1200)
|
50 |
+
negative_prompt = gr.Checkbox(label='Negative Prompt', value=False)
|
51 |
gen_button = gr.Button('Generate up to 150 images in up to 3 minutes total')
|
52 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False)
|
53 |
+
|
54 |
+
# Evento de clique para iniciar a geração de imagens
|
55 |
+
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
|
56 |
+
|
57 |
gr.HTML(
|
58 |
+
"""
|
59 |
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
60 |
<div>
|
61 |
<body>
|
|
|
64 |
</body>
|
65 |
</div>
|
66 |
</div>
|
67 |
+
"""
|
68 |
+
)
|
69 |
+
|
70 |
with gr.Row():
|
71 |
+
output = [gr.Image(label=m, min_width=512) for m in default_models]
|
72 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
73 |
+
|
74 |
for m, o in zip(current_models, output):
|
75 |
+
# Evento de clique para gerar imagens para cada modelo selecionado
|
76 |
+
gen_event = gen_button.click(generate_images, [m, txt_input, negative_prompt], o)
|
77 |
+
# Evento de clique para parar a geração de imagens
|
78 |
+
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
79 |
+
|
80 |
with gr.Accordion('Model selection'):
|
81 |
+
model_choice = gr.CheckboxGroup(
|
82 |
+
models,
|
83 |
+
label=f'Choose up to {num_models} different models from the available options!',
|
84 |
+
value=default_models,
|
85 |
+
multiselect=True,
|
86 |
+
max_choices=num_models,
|
87 |
+
interactive=True,
|
88 |
+
filterable=False
|
89 |
+
)
|
90 |
+
|
91 |
+
# Evento de mudança para atualizar a caixa de imagens com base nas escolhas
|
92 |
model_choice.change(update_imgbox, model_choice, output)
|
93 |
model_choice.change(extend_choices, model_choice, current_models)
|
94 |
+
|
95 |
with gr.Row():
|
96 |
gr.HTML(
|
97 |
+
"""
|
98 |
+
<div class="footer">
|
99 |
+
<p> Based on the <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier!
|
100 |
+
</p>
|
101 |
+
"""
|
102 |
+
)
|
103 |
+
|
104 |
+
demo.queue(concurrency_count=200)
|
105 |
+
demo.launch()
|