app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,11 @@ from random import randint
|
|
3 |
from all_models import models
|
4 |
from datetime import datetime
|
5 |
|
6 |
-
now2 = 0
|
7 |
-
|
8 |
-
|
9 |
def get_current_time():
|
10 |
now = datetime.now()
|
11 |
now2 = now
|
12 |
current_time = now2.strftime("%Y-%m-%d %H:%M:%S")
|
13 |
-
ki = f'{
|
14 |
return ki
|
15 |
|
16 |
def load_fn(models):
|
@@ -34,57 +31,199 @@ def extend_choices(choices):
|
|
34 |
|
35 |
def update_imgbox(choices):
|
36 |
choices_plus = extend_choices(choices)
|
37 |
-
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
38 |
|
39 |
def gen_fn(model_str, prompt):
|
40 |
if model_str == 'NA':
|
41 |
return None
|
42 |
-
noise = str(randint(0,
|
43 |
return models_load[model_str](f'{prompt} {noise}')
|
44 |
|
45 |
def make_me():
|
46 |
-
|
47 |
-
with gr.
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
output = [gr.Image(label=m, min_width=250, height=250) for m in default_models]
|
62 |
-
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
63 |
-
for m, o in zip(current_models, output):
|
64 |
-
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
65 |
-
stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
|
66 |
-
with gr.Accordion('Model selection'):
|
67 |
-
model_choice = gr.CheckboxGroup(models, label=f' {num_models} different models selected', value=default_models, multiselect=True, max_choices=num_models, interactive=True, filterable=False)
|
68 |
-
model_choice.change(update_imgbox, model_choice, output)
|
69 |
-
model_choice.change(extend_choices, model_choice, current_models)
|
70 |
-
with gr.Row():
|
71 |
-
gr.HTML()
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
js_code = """
|
76 |
-
|
77 |
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
"""
|
81 |
|
82 |
-
|
83 |
-
with gr.Blocks(css="div.float.svelte-1mwvhlq { position: absolute; top: var(--block-label-margin); left: var(--block-label-margin); background: none; border: none;}") as demo:
|
84 |
-
gr.Markdown("<script>" + js_code + "</script>")
|
85 |
make_me()
|
86 |
|
87 |
-
|
88 |
-
|
89 |
demo.queue(concurrency_count=100)
|
90 |
-
demo.launch()
|
|
|
3 |
from all_models import models
|
4 |
from datetime import datetime
|
5 |
|
|
|
|
|
|
|
6 |
def get_current_time():
|
7 |
now = datetime.now()
|
8 |
now2 = now
|
9 |
current_time = now2.strftime("%Y-%m-%d %H:%M:%S")
|
10 |
+
ki = f'{current_time}'
|
11 |
return ki
|
12 |
|
13 |
def load_fn(models):
|
|
|
31 |
|
32 |
def update_imgbox(choices):
|
33 |
choices_plus = extend_choices(choices)
|
34 |
+
return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
|
35 |
|
36 |
def gen_fn(model_str, prompt):
|
37 |
if model_str == 'NA':
|
38 |
return None
|
39 |
+
noise = str(randint(0, 9999999))
|
40 |
return models_load[model_str](f'{prompt} {noise}')
|
41 |
|
42 |
def make_me():
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column(scale=1):
|
45 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
46 |
+
with gr.Row():
|
47 |
+
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
48 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
49 |
+
|
50 |
+
def on_generate_click():
|
51 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
|
52 |
+
|
53 |
+
def on_stop_click():
|
54 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
55 |
+
|
56 |
+
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
57 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
with gr.Row():
|
60 |
+
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
61 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
62 |
+
for m, o in zip(current_models, output):
|
63 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input], o)
|
64 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
65 |
+
|
66 |
+
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
67 |
+
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
68 |
+
model_choice.change(update_imgbox, model_choice, output)
|
69 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
70 |
+
|
71 |
+
with gr.Row():
|
72 |
+
gr.HTML("")
|
73 |
+
|
74 |
+
custom_css = """
|
75 |
+
:root {
|
76 |
+
--body-background-fill: #2d3d4f;
|
77 |
+
}
|
78 |
+
body {
|
79 |
+
background-color: var(--body-background-fill) !important;
|
80 |
+
color: #2d3d4f;
|
81 |
+
margin: 0;
|
82 |
+
padding: 0;
|
83 |
+
font-family: Arial, sans-serif;
|
84 |
+
height: 100vh;
|
85 |
+
overflow-y: auto;
|
86 |
+
}
|
87 |
+
.gradio-container {
|
88 |
+
background-color: #2d3d4f;
|
89 |
+
color: #c5c6c7;
|
90 |
+
padding: 20px;
|
91 |
+
border-radius: 8px;
|
92 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
93 |
+
width: 100%;
|
94 |
+
max-width: 1200px;
|
95 |
+
margin: 20px auto;
|
96 |
+
display: block;
|
97 |
+
min-height: 100vh;
|
98 |
+
}
|
99 |
+
.app_title {
|
100 |
+
background-color: #2d3d4f;
|
101 |
+
color: #c5c6c7;
|
102 |
+
padding: 10px 20px;
|
103 |
+
border-bottom: 1px solid #3b4252;
|
104 |
+
text-align: center;
|
105 |
+
font-size: 24px;
|
106 |
+
font-weight: bold;
|
107 |
+
width: 100%;
|
108 |
+
box-sizing: border-box;
|
109 |
+
margin-bottom: 20px;
|
110 |
+
}
|
111 |
+
.custom_textbox {
|
112 |
+
background-color: #2d343f;
|
113 |
+
border: 1px solid #3b4252;
|
114 |
+
color: #7f8184;
|
115 |
+
padding: 10px;
|
116 |
+
border-radius: 4px;
|
117 |
+
margin-bottom: 10px;
|
118 |
+
width: 100%;
|
119 |
+
box-sizing: border-box;
|
120 |
+
}
|
121 |
+
.custom_gen_button {
|
122 |
+
background-color: #8b38ff;
|
123 |
+
border: 1px solid #ffffff;
|
124 |
+
color: blue;
|
125 |
+
padding: 15px 32px;
|
126 |
+
text-align: center;
|
127 |
+
text-decoration: none;
|
128 |
+
display: inline-block;
|
129 |
+
font-size: 16px;
|
130 |
+
margin: 4px 2px;
|
131 |
+
cursor: pointer;
|
132 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
133 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
134 |
+
border-radius: 4px;
|
135 |
+
}
|
136 |
+
.custom_gen_button:hover {
|
137 |
+
transform: translateY(-2px);
|
138 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
139 |
+
}
|
140 |
+
.custom_stop_button {
|
141 |
+
background-color: #6200ea;
|
142 |
+
border: 1px solid #ffffff;
|
143 |
+
color: blue;
|
144 |
+
padding: 15px 32px;
|
145 |
+
text-align: center;
|
146 |
+
text-decoration: none;
|
147 |
+
display: inline-block;
|
148 |
+
font-size: 16px;
|
149 |
+
margin: 4px 2px;
|
150 |
+
cursor: pointer;
|
151 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
152 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
153 |
+
border-radius: 4px;
|
154 |
+
}
|
155 |
+
.custom_stop_button:hover {
|
156 |
+
transform: translateY(-2px);
|
157 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
158 |
+
}
|
159 |
+
.custom_image {
|
160 |
+
border: 1px solid #3b4252;
|
161 |
+
background-color: #2d343f;
|
162 |
+
border-radius: 4px;
|
163 |
+
margin: 10px;
|
164 |
+
max-width: 100%;
|
165 |
+
box-sizing: border-box;
|
166 |
+
}
|
167 |
+
.custom_accordion {
|
168 |
+
background-color: #2d3d4f;
|
169 |
+
color: #7f8184;
|
170 |
+
border: 1px solid #3b4252;
|
171 |
+
border-radius: 4px;
|
172 |
+
margin-top: 20px;
|
173 |
+
width: 100%;
|
174 |
+
box-sizing: border-box;
|
175 |
+
transition: margin 0.2s ease;
|
176 |
+
}
|
177 |
+
.custom_accordion .gr-accordion-header {
|
178 |
+
background-color: #2d3d4f;
|
179 |
+
color: #7f8184;
|
180 |
+
padding: 10px 20px;
|
181 |
+
border-bottom: 1px solid #5b6270;
|
182 |
+
cursor: pointer;
|
183 |
+
font-size: 18px;
|
184 |
+
font-weight: bold;
|
185 |
+
height: 40px;
|
186 |
+
display: flex;
|
187 |
+
align-items: center;
|
188 |
+
}
|
189 |
+
.custom_accordion .gr-accordion-header:hover {
|
190 |
+
background-color: #2d3d4f;
|
191 |
+
}
|
192 |
+
.custom_accordion .gr-accordion-content {
|
193 |
+
padding: 10px 20px;
|
194 |
+
background-color: #2d3d4f;
|
195 |
+
border-top: 1px solid #5b6270;
|
196 |
+
max-height: 0;
|
197 |
+
overflow: hidden;
|
198 |
+
transition: max-height 0.2s ease;
|
199 |
+
}
|
200 |
+
.custom_accordion .gr-accordion-content.open {
|
201 |
+
max-height: 500px;
|
202 |
+
}
|
203 |
+
.custom_checkbox_group {
|
204 |
+
background-color: #2d343f;
|
205 |
+
border: 1px solid #3b4252;
|
206 |
+
color: #7f8184;
|
207 |
+
border-radius: 4px;
|
208 |
+
padding: 10px;
|
209 |
+
width: 100%;
|
210 |
+
box-sizing: border-box;
|
211 |
+
}
|
212 |
+
@media (max-width: 768px) {
|
213 |
+
.gradio-container {
|
214 |
+
width: 100%;
|
215 |
+
margin: 0;
|
216 |
+
padding: 10px;
|
217 |
+
}
|
218 |
+
.custom_textbox,.custom_image,.custom_checkbox_group {
|
219 |
+
width: 100%;
|
220 |
+
box-sizing: border-box;
|
221 |
+
}
|
222 |
+
}
|
223 |
"""
|
224 |
|
225 |
+
with gr.Blocks(css=custom_css) as demo:
|
|
|
|
|
226 |
make_me()
|
227 |
|
|
|
|
|
228 |
demo.queue(concurrency_count=100)
|
229 |
+
demo.launch()
|