LeeveWasTaken
commited on
Commit
•
3c0b2e4
1
Parent(s):
420fff6
Update app.py
Browse files
app.py
CHANGED
@@ -1,82 +1,70 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
from all_models import models
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
MODELS_LOADED = load_models(models)
|
18 |
-
|
19 |
def extend_choices(choices):
|
20 |
-
return choices +
|
21 |
-
|
22 |
def update_imgbox(choices):
|
23 |
-
|
24 |
-
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in
|
25 |
-
|
26 |
def gen_fn(model_str, prompt, negative_prompt=None, image_style="Default"):
|
27 |
if model_str == 'NA':
|
28 |
return None
|
29 |
-
modified_prompt =
|
|
|
|
|
30 |
if negative_prompt:
|
31 |
modified_prompt += f", not {negative_prompt}"
|
32 |
-
return
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
with gr.
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
"""
|
49 |
-
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
50 |
-
<p style="margin-bottom: 10px; color: var(--body-text-color);">Scroll down to see more images and select models.</p>
|
51 |
</div>
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
model_choice.change(extend_choices, model_choice, current_models)
|
69 |
-
|
70 |
gr.HTML(
|
71 |
-
|
72 |
<div class="footer">
|
73 |
-
|
74 |
-
</
|
75 |
-
|
76 |
)
|
77 |
-
|
78 |
-
return demo
|
79 |
-
|
80 |
-
if __name__ == "__main__":
|
81 |
-
demo = create_interface()
|
82 |
-
demo.launch(max_threads=200)
|
|
|
1 |
import gradio as gr
|
2 |
+
from random import randint
|
3 |
from all_models import models
|
4 |
+
def load_fn(models):
|
5 |
+
global models_load
|
6 |
+
models_load = {}
|
7 |
+
for model in models:
|
8 |
+
if model not in models_load.keys():
|
9 |
+
try:
|
10 |
+
m = gr.load(f'models/{model}')
|
11 |
+
except Exception as error:
|
12 |
+
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
13 |
+
models_load.update({model: m})
|
14 |
+
load_fn(models)
|
15 |
+
num_models = 6
|
16 |
+
default_models = models[:num_models]
|
|
|
|
|
17 |
def extend_choices(choices):
|
18 |
+
return choices + (num_models - len(choices)) * ['NA']
|
|
|
19 |
def update_imgbox(choices):
|
20 |
+
choices_plus = extend_choices(choices)
|
21 |
+
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
|
|
22 |
def gen_fn(model_str, prompt, negative_prompt=None, image_style="Default"):
|
23 |
if model_str == 'NA':
|
24 |
return None
|
25 |
+
modified_prompt = prompt
|
26 |
+
if image_style != "Default":
|
27 |
+
modified_prompt += f", {image_style}"
|
28 |
if negative_prompt:
|
29 |
modified_prompt += f", not {negative_prompt}"
|
30 |
+
return models_load[model_str](modified_prompt)
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
with gr.Tab('The Dream'):
|
33 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=4)
|
34 |
+
with gr.Accordion("Advanced Settings", open=False) as advanced_settings:
|
35 |
+
neg_prompt = gr.Textbox(label='Negative prompt (Optional):', placeholder='Enter undesirable attributes here', lines=2)
|
36 |
+
image_style = gr.Dropdown(label='Select Style', choices=["Default", "Realistic", "Portrait", "Anime"], value="Default")
|
37 |
+
gen_button = gr.Button('Generate up to 6 images in up to 2 minutes total')
|
38 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False)
|
39 |
+
gen_button.click(lambda s: gr.update(interactive=True), None, stop_button, concurrency_limit=10)
|
40 |
+
gr.HTML(
|
41 |
+
"""
|
42 |
+
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
43 |
+
<div>
|
44 |
+
<body>
|
45 |
+
<div class="center"><p style="margin-bottom: 10px; color: var(--body-text-color);">Scroll down to see more images and select models.</p>
|
|
|
|
|
|
|
46 |
</div>
|
47 |
+
</body>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
"""
|
51 |
+
)
|
52 |
+
with gr.Row():
|
53 |
+
output = [gr.Image(label=m, min_width=460) for m in default_models]
|
54 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
55 |
+
for m, o in zip(current_models, output):
|
56 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, neg_prompt, image_style], o, concurrency_limit=10)
|
57 |
+
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
58 |
+
with gr.Accordion('Model selection'):
|
59 |
+
model_choice = gr.CheckboxGroup(models, label=f'Choose up to {num_models} different models from the best available!', value=default_models, interactive=True)
|
60 |
+
model_choice.change(update_imgbox, model_choice, output)
|
61 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
62 |
+
with gr.Row():
|
|
|
|
|
63 |
gr.HTML(
|
64 |
+
"""
|
65 |
<div class="footer">
|
66 |
+
<p>Have fun!
|
67 |
+
</p>
|
68 |
+
"""
|
69 |
)
|
70 |
+
demo.launch(max_threads=200)
|
|
|
|
|
|
|
|
|
|