Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,168 +1,84 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
|
3 |
-
def p(command):
|
4 |
-
print("EXEC: " + command)
|
5 |
-
os.system(command)
|
6 |
|
7 |
-
p("mkdir _gradio")
|
8 |
-
p("mv Gradio.zip _gradio")
|
9 |
-
os.chdir("_gradio")
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
z = ZipFile("Gradio.zip")
|
14 |
-
z.extractall()
|
15 |
-
p("pip install -e .")
|
16 |
-
print(os.getcwd())
|
17 |
-
import sys
|
18 |
-
sys.path.append(os.getcwd())
|
19 |
-
os.chdir("..")
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
|
28 |
-
#text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
|
29 |
-
text_gen1=gr.Interface.load("spaces/Yntec/prompt-extend")
|
30 |
-
#text_gen1=gr.Interface.load("spaces/daspartho/prompt-extend")
|
31 |
-
#text_gen1=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
gr.Interface.load(f"models/{models[1]}",live=False,preprocess=True, postprocess=False),
|
36 |
-
gr.Interface.load(f"models/{models[2]}",live=False,preprocess=True, postprocess=False),
|
37 |
-
gr.Interface.load(f"models/{models[3]}",live=False,preprocess=True, postprocess=False),
|
38 |
-
gr.Interface.load(f"models/{models[4]}",live=False,preprocess=True, postprocess=False),
|
39 |
-
gr.Interface.load(f"models/{models[5]}",live=False,preprocess=True, postprocess=False),
|
40 |
-
#Because there's a model 0, to know the number of models you add 1 to {models[n]}
|
41 |
-
]
|
42 |
|
43 |
-
def text_it1(inputs,text_gen1=text_gen1):
|
44 |
-
go_t1=text_gen1(inputs)
|
45 |
-
return(go_t1)
|
46 |
|
47 |
-
def
|
48 |
-
|
49 |
-
return gr.
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
def send_it1(inputs, model_choice): #negative_prompt,
|
53 |
-
proc1=models2[model_choice]
|
54 |
-
output1=proc1(inputs)
|
55 |
-
#negative_prompt=negative_prompt
|
56 |
-
return(output1)
|
57 |
-
css=""""""
|
58 |
|
59 |
|
60 |
-
with gr.Blocks(
|
61 |
-
gr.
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
<div>
|
64 |
-
<style>
|
65 |
-
h1 {
|
66 |
-
font-size: 6em;
|
67 |
-
color: #c9c9c9;
|
68 |
-
margin-top: 30px;
|
69 |
-
margin-bottom: 30px;
|
70 |
-
text-shadow: 3px 3px 0 rgba(0, 0, 0, 1) !important;
|
71 |
-
}
|
72 |
-
h3 {
|
73 |
-
color: #c9c9c9; !important;
|
74 |
-
}
|
75 |
-
h4 {
|
76 |
-
color: #ffffff; !important;
|
77 |
-
}
|
78 |
-
.gradio-container {
|
79 |
-
background-image: linear-gradient(#252525, #1e1e1e, #181818) !important;
|
80 |
-
color: #aaaaaa !important;
|
81 |
-
font-family: 'IBM Plex Sans', sans-serif !important;
|
82 |
-
}
|
83 |
-
.text-gray-500 {
|
84 |
-
color: #c9c9c9 !important;
|
85 |
-
}
|
86 |
-
.gr-box {
|
87 |
-
background-image: linear-gradient(#181818, #1e1e1e, #252525) !important;
|
88 |
-
border-top-color: #000000 !important;
|
89 |
-
border-right-color: #ffffff !important;
|
90 |
-
border-bottom-color: #ffffff !important;
|
91 |
-
border-left-color: #000000 !important;
|
92 |
-
}
|
93 |
-
.gr-input {
|
94 |
-
color: #c9c9c9; !important;
|
95 |
-
background-color: #252525 !important;
|
96 |
-
}
|
97 |
-
:root {
|
98 |
-
--neutral-100: #000000 !important;
|
99 |
-
}
|
100 |
-
</style>
|
101 |
<body>
|
102 |
-
<div class="center"><
|
103 |
</div>
|
104 |
</body>
|
105 |
</div>
|
106 |
-
<p style="margin-bottom: 9px; color: #aaaaaa;">
|
107 |
-
<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>
|
108 |
</div>
|
109 |
-
|
110 |
-
|
111 |
-
with gr.
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
gr.
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
.
|
132 |
-
|
133 |
-
font-size: 98% !important;
|
134 |
-
text-shadow: 0px 0px 0 rgba(0, 0, 0, 1) !important;
|
135 |
-
background-image: linear-gradient(#a489d2, #635a76) !important;
|
136 |
-
border-top-color: #000000 !important;
|
137 |
-
border-right-color: #ffffff !important;
|
138 |
-
border-bottom-color: #ffffff !important;
|
139 |
-
border-left-color: #000000 !important;
|
140 |
-
}
|
141 |
-
.gr-button:hover {
|
142 |
-
filter: brightness(130%);
|
143 |
-
}
|
144 |
-
</style>""")
|
145 |
-
run=gr.Button("Generate Image")
|
146 |
-
with gr.Row():
|
147 |
-
with gr.Column(style="width=800px"):
|
148 |
-
output1=gr.Image(label=(f"{current_model}"))
|
149 |
-
|
150 |
-
|
151 |
-
with gr.Row():
|
152 |
-
with gr.Column(scale=50):
|
153 |
-
input_text=gr.Textbox(label="Use this box to extend an idea automagically, by typing some words and clicking Extend Idea",lines=2)
|
154 |
-
see_prompts=gr.Button("Extend Idea -> overwrite the contents of the `Your Prompt´ box above")
|
155 |
-
use_short=gr.Button("Copy the contents of this box to the `Your Prompt´ box above")
|
156 |
-
def short_prompt(inputs):
|
157 |
-
return(inputs)
|
158 |
-
|
159 |
-
model_name1.change(set_model,inputs=model_name1,outputs=[output1])
|
160 |
-
|
161 |
-
run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
|
162 |
-
|
163 |
-
use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
|
164 |
-
|
165 |
-
see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
|
166 |
-
|
167 |
-
myface.queue(concurrency_count=200)
|
168 |
-
myface.launch(inline=True, show_api=False, max_threads=400)
|
|
|
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
|
9 |
+
models_load = {}
|
10 |
+
|
11 |
+
for model in models:
|
12 |
+
if model not in models_load.keys():
|
13 |
+
try:
|
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 |
+
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 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"><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=480) 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 686 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 |
+
<div class="footer">
|
78 |
+
<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!
|
79 |
+
</p>
|
80 |
+
"""
|
81 |
+
)
|
82 |
+
|
83 |
+
demo.queue(concurrency_count = 200)
|
84 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|