Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from random import randint
|
| 3 |
from all_models import models
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 6 |
|
| 7 |
def load_fn(models):
|
| 8 |
global models_load
|
|
@@ -13,72 +19,92 @@ def load_fn(models):
|
|
| 13 |
try:
|
| 14 |
m = gr.load(f'models/{model}')
|
| 15 |
except Exception as error:
|
| 16 |
-
m =
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
load_fn(models)
|
| 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)) * ['NA']
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def update_imgbox(choices):
|
| 33 |
-
choices_plus = extend_choices(choices)
|
| 34 |
-
return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def gen_fn(model_str, prompt):
|
| 38 |
-
if model_str == 'NA':
|
| 39 |
-
return None
|
| 40 |
-
noise = str('') #str(randint(0, 99999999999))
|
| 41 |
-
return models_load[model_str](f'{prompt} {noise}')
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
with gr.Blocks() as demo:
|
| 46 |
-
with gr.Tab('The Dream'):
|
| 47 |
-
txt_input = gr.Textbox(label = 'Your prompt:', lines=4).style(container=False,min_width=1200)
|
| 48 |
-
gen_button = gr.Button('Generate up to 150 images in up to 3 minutes total')
|
| 49 |
-
stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
|
| 50 |
-
gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
|
| 51 |
-
gr.HTML(
|
| 52 |
-
"""
|
| 53 |
-
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
| 54 |
-
<div>
|
| 55 |
-
<body>
|
| 56 |
-
<div class="center"><p style="margin-bottom: 10px; color: #000000;">Scroll down to see more images and select models.</p>
|
| 57 |
-
</div>
|
| 58 |
-
</body>
|
| 59 |
-
</div>
|
| 60 |
-
</div>
|
| 61 |
-
"""
|
| 62 |
-
)
|
| 63 |
-
with gr.Row():
|
| 64 |
-
output = [gr.Image(label = m, min_width=768) for m in default_models]
|
| 65 |
-
current_models = [gr.Textbox(m, visible = False) for m in default_models]
|
| 66 |
-
|
| 67 |
-
for m, o in zip(current_models, output):
|
| 68 |
-
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
| 69 |
-
stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
|
| 70 |
-
with gr.Accordion('Model selection'):
|
| 71 |
-
model_choice = gr.CheckboxGroup(models, label = f'Choose up to {num_models} different models from the 755 available!', value = default_models, multiselect = True, max_choices = num_models, interactive = True, filterable = False)
|
| 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 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from random import randint
|
| 3 |
from all_models import models
|
| 4 |
+
from gradio import Interface
|
| 5 |
|
| 6 |
+
# Define Bootstrap CSS styles
|
| 7 |
+
bootstrap_css = """
|
| 8 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqO4aIfeHaHNVy2QWhv2P+nvf4jCF0S42kqR8YcOrHndjw6qplMFZrk" crossorigin="anonymous">
|
| 9 |
+
"""
|
| 10 |
|
| 11 |
+
gr.Config.css = [bootstrap_css]
|
| 12 |
|
| 13 |
def load_fn(models):
|
| 14 |
global models_load
|
|
|
|
| 19 |
try:
|
| 20 |
m = gr.load(f'models/{model}')
|
| 21 |
except Exception as error:
|
| 22 |
+
m = Interface(lambda txt: None, ['text'], ['image'])
|
| 23 |
+
models_Multiplier = {model: m}
|
| 24 |
+
|
| 25 |
+
load_fn(models)
|
| 26 |
+
|
| 27 |
+
num_models = 150
|
| 28 |
+
default_models = models[:num_models]
|
| 29 |
+
|
| 30 |
+
def extend_choices(choices):
|
| 31 |
+
return choices + (num_models - len(choices)) * ['NA']
|
| 32 |
+
|
| 33 |
+
def update_imgbox(choices):
|
| 34 |
+
choices_plus = extend_choices(choices)
|
| 35 |
+
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
| 36 |
+
|
| 37 |
+
def gen_fn(model_str, prompt):
|
| 38 |
+
if model_str == 'NA':
|
| 39 |
+
return None
|
| 40 |
+
noise = str(randint(0, 99999999999))
|
| 41 |
+
return models_load[model_str](f'{prompt} {noise}')
|
| 42 |
+
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
with gr.Tab('The Dream'):
|
| 45 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=4).style(
|
| 46 |
+
'text-align: left;',
|
| 47 |
+
'width: 100%;',
|
| 48 |
+
'margin-bottom: 20px;',
|
| 49 |
+
'font-size: 16px;'
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
gen_button = gr.Button(
|
| 53 |
+
'Generate up to 150 images in up to 3 minutes total',
|
| 54 |
+
style='margin-bottom: 20px;'
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
stop_button = gr.Button(
|
| 58 |
+
'Stop',
|
| 59 |
+
variant='danger',
|
| 60 |
+
interactive=False,
|
| 61 |
+
style='margin-bottom: 20px;'
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
gr.HTML(
|
| 67 |
+
"""
|
| 68 |
+
<div style="text-align: left; max-width: 800px; margin: 0 auto;">
|
| 69 |
+
<p style="margin-bottom: 10px; color: #333333;">Enter your prompt in the text box and click "Generate" to start generating images.</p>
|
| 70 |
+
</div>
|
| 71 |
+
"""
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
with gr.Row():
|
| 75 |
+
output = [gr.Image(label=m, min_width=250) for m in default_models]
|
| 76 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
| 77 |
+
|
| 78 |
+
for m, o in zip(current_models, output):
|
| 79 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
| 80 |
+
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
| 81 |
+
|
| 82 |
+
with gr.Accordion('Model selection'):
|
| 83 |
+
model_choice = gr.CheckboxGroup(
|
| 84 |
+
models,
|
| 85 |
+
label=f'Choose up to {num_models} different models out of {len(models)} available!',
|
| 86 |
+
value=default_models,
|
| 87 |
+
multiselect=True,
|
| 88 |
+
max_choices=num_models,
|
| 89 |
+
interactive=True,
|
| 90 |
+
filterable=True,
|
| 91 |
+
style='width: 100%;'
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
model_choice.change(update_imgbox, model_choice, output)
|
| 95 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
| 96 |
+
|
| 97 |
+
with gr.Row():
|
| 98 |
+
gr.HTML(
|
| 99 |
+
"""
|
| 100 |
+
<div class="footer">
|
| 101 |
+
<p style="font-size: 14px; color: #666666;">
|
| 102 |
+
Based on the <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn,
|
| 103 |
+
the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier!
|
| 104 |
+
</p>
|
| 105 |
+
</div>
|
| 106 |
+
"""
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
demo.queue(concurrency_count=200)
|
| 110 |
+
demo.launch()
|