Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,84 +1,151 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
3 |
from all_models import models
|
|
|
|
|
4 |
|
5 |
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
m = gr.load(f'models/{model}')
|
15 |
-
except Exception as error:
|
16 |
-
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
17 |
-
models_load.update({model: m})
|
18 |
-
|
19 |
-
|
20 |
-
load_fn(models)
|
21 |
-
|
22 |
-
|
23 |
-
num_models = 6
|
24 |
-
default_models = models[:num_models]
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
|
|
|
|
|
|
|
31 |
|
32 |
-
def
|
33 |
-
|
34 |
-
return
|
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
|
46 |
-
|
47 |
-
|
48 |
-
gen_button = gr.Button('Generate up to 6 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"><
|
57 |
</div>
|
58 |
</body>
|
59 |
</div>
|
|
|
|
|
60 |
</div>
|
61 |
-
|
62 |
-
|
63 |
-
with gr.
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
from pathlib import Path
|
5 |
from all_models import models
|
6 |
+
|
7 |
+
current_model = models[0]
|
8 |
|
9 |
|
10 |
+
#text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
|
11 |
+
text_gen1=gr.Interface.load("spaces/Yntec/prompt-extend")
|
12 |
+
#text_gen1=gr.Interface.load("spaces/daspartho/prompt-extend")
|
13 |
+
#text_gen1=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
|
14 |
|
15 |
+
models2=[
|
16 |
+
gr.Interface.load(f"models/{models[0]}",live=False,preprocess=True, postprocess=False),
|
17 |
+
gr.Interface.load(f"models/{models[1]}",live=False,preprocess=True, postprocess=False),
|
18 |
+
gr.Interface.load(f"models/{models[2]}",live=False,preprocess=True, postprocess=False),
|
19 |
+
gr.Interface.load(f"models/{models[3]}",live=False,preprocess=True, postprocess=False),
|
20 |
+
gr.Interface.load(f"models/{models[4]}",live=False,preprocess=True, postprocess=False),
|
21 |
+
gr.Interface.load(f"models/{models[5]}",live=False,preprocess=True, postprocess=False),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
#Because there's a model 0, to know the number of models you add 1 to {models[n]}
|
24 |
+
]
|
25 |
|
26 |
+
def text_it1(inputs,text_gen1=text_gen1):
|
27 |
+
go_t1=text_gen1(inputs)
|
28 |
+
return(go_t1)
|
29 |
|
30 |
+
def set_model(current_model):
|
31 |
+
current_model = models[current_model]
|
32 |
+
return gr.update(label=(f"{current_model}"))
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
def send_it1(inputs, model_choice): #negative_prompt,
|
36 |
+
proc1=models2[model_choice]
|
37 |
+
output1=proc1(inputs)
|
38 |
+
#negative_prompt=negative_prompt
|
39 |
+
return(output1)
|
40 |
+
css=""""""
|
41 |
|
42 |
|
43 |
+
with gr.Blocks(css=css) as myface:
|
44 |
+
gr.HTML("""
|
45 |
+
<div style="text-align: center; max-width: 1200px; margin: 0 auto;">
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
<div>
|
47 |
+
<style>
|
48 |
+
h1 {
|
49 |
+
font-size: 6em;
|
50 |
+
color: #c9c9c9;
|
51 |
+
margin-top: 30px;
|
52 |
+
margin-bottom: 30px;
|
53 |
+
text-shadow: 3px 3px 0 rgba(0, 0, 0, 1) !important;
|
54 |
+
}
|
55 |
+
h3 {
|
56 |
+
color: #c9c9c9; !important;
|
57 |
+
}
|
58 |
+
h4 {
|
59 |
+
color: #ffffff; !important;
|
60 |
+
}
|
61 |
+
.gradio-container {
|
62 |
+
background-image: linear-gradient(#252525, #1e1e1e, #181818) !important;
|
63 |
+
color: #aaaaaa !important;
|
64 |
+
font-family: 'IBM Plex Sans', sans-serif !important;
|
65 |
+
}
|
66 |
+
.text-gray-500 {
|
67 |
+
color: #c9c9c9 !important;
|
68 |
+
}
|
69 |
+
.gr-box {
|
70 |
+
background-image: linear-gradient(#181818, #1e1e1e, #252525) !important;
|
71 |
+
border-top-color: #000000 !important;
|
72 |
+
border-right-color: #ffffff !important;
|
73 |
+
border-bottom-color: #ffffff !important;
|
74 |
+
border-left-color: #000000 !important;
|
75 |
+
}
|
76 |
+
.gr-input {
|
77 |
+
color: #c9c9c9; !important;
|
78 |
+
background-color: #252525 !important;
|
79 |
+
}
|
80 |
+
:root {
|
81 |
+
--neutral-100: #000000 !important;
|
82 |
+
}
|
83 |
+
</style>
|
84 |
<body>
|
85 |
+
<div class="center"><h1>Printing Press</h1>
|
86 |
</div>
|
87 |
</body>
|
88 |
</div>
|
89 |
+
<p style="margin-bottom: 9px; color: #aaaaaa;">
|
90 |
+
<h3>Top 684 Blitz Diffusion Models - A permanently online (unless huggingface is acting up, ha!) backup copy of <a href="https://huggingface.co/spaces/Yntec/ToyWorld"><u><p style="color:#8150df;"><b>Toy World!</b></p></u></a></h3></p>
|
91 |
</div>
|
92 |
+
""")
|
93 |
+
with gr.Row():
|
94 |
+
with gr.Column(scale=100):
|
95 |
+
#Model selection dropdown
|
96 |
+
model_name1 = gr.Dropdown(label="Select Model", choices=[m for m in models], type="index", value=current_model, interactive=True)
|
97 |
+
with gr.Row():
|
98 |
+
with gr.Column(scale=100):
|
99 |
+
magic1=gr.Textbox(label="Your Prompt", lines=4) #Positive
|
100 |
+
#with gr.Column(scale=100):
|
101 |
+
#negative_prompt=gr.Textbox(label="Negative Prompt", lines=1)
|
102 |
+
gr.HTML("""<style> .gr-button {
|
103 |
+
color: #ffffff !important;
|
104 |
+
text-shadow: 1px 1px 0 rgba(0, 0, 0, 1) !important;
|
105 |
+
background-image: linear-gradient(#635a76, #a489d2) !important;
|
106 |
+
border-radius: 24px !important;
|
107 |
+
border: solid 1px !important;
|
108 |
+
border-top-color: #c99fff !important;
|
109 |
+
border-right-color: #000000 !important;
|
110 |
+
border-bottom-color: #000000 !important;
|
111 |
+
border-left-color: #c99fff !important;
|
112 |
+
padding: 6px 30px;
|
113 |
+
}
|
114 |
+
.gr-button:active {
|
115 |
+
color: #c99fff !important;
|
116 |
+
font-size: 98% !important;
|
117 |
+
text-shadow: 0px 0px 0 rgba(0, 0, 0, 1) !important;
|
118 |
+
background-image: linear-gradient(#a489d2, #635a76) !important;
|
119 |
+
border-top-color: #000000 !important;
|
120 |
+
border-right-color: #ffffff !important;
|
121 |
+
border-bottom-color: #ffffff !important;
|
122 |
+
border-left-color: #000000 !important;
|
123 |
+
}
|
124 |
+
.gr-button:hover {
|
125 |
+
filter: brightness(130%);
|
126 |
+
}
|
127 |
+
</style>""")
|
128 |
+
run=gr.Button("Generate Image")
|
129 |
+
with gr.Row():
|
130 |
+
with gr.Column(style="width=800px"):
|
131 |
+
output1=gr.Image(label=(f"{current_model}"))
|
132 |
+
|
133 |
+
|
134 |
+
with gr.Row():
|
135 |
+
with gr.Column(scale=50):
|
136 |
+
input_text=gr.Textbox(label="Use this box to extend an idea automagically, by typing some words and clicking Extend Idea",lines=2)
|
137 |
+
see_prompts=gr.Button("Extend Idea -> overwrite the contents of the `Your Prompt´ box above")
|
138 |
+
use_short=gr.Button("Copy the contents of this box to the `Your Prompt´ box above")
|
139 |
+
def short_prompt(inputs):
|
140 |
+
return(inputs)
|
141 |
+
|
142 |
+
model_name1.change(set_model,inputs=model_name1,outputs=[output1])
|
143 |
+
|
144 |
+
run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
|
145 |
+
|
146 |
+
use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
|
147 |
+
|
148 |
+
see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
|
149 |
+
|
150 |
+
myface.queue(concurrency_count=200)
|
151 |
+
myface.launch(inline=True, show_api=False, max_threads=400)
|