DazDin commited on
Commit
676e1c4
·
verified ·
1 Parent(s): 0b4aa7f
Files changed (1) hide show
  1. app.py +183 -27
app.py CHANGED
@@ -2,18 +2,17 @@ import gradio as gr
2
  from random import randint
3
  from all_models import models
4
 
5
- def load_fn(models):
 
6
  global models_load
7
- models_load = {}
8
  for model in models:
9
- if model not in models_load.keys():
10
- try:
11
- m = gr.load(f'models/{model}')
12
- except Exception as error:
13
- m = gr.Interface(lambda txt: None, ['text'], ['image'])
14
- models_load.update({model: m})
15
 
16
- load_fn(models)
17
 
18
  num_models = len(models)
19
  default_models = models[:num_models]
@@ -28,25 +27,31 @@ def update_imgbox(choices):
28
  def gen_fn(model_str, prompt):
29
  if model_str == 'NA':
30
  return None
31
- noise = str(randint(0, 9999999))
32
- return models_load[model_str](f'{prompt} {noise}')
33
 
34
  def make_me():
35
  with gr.Row():
36
- with gr.Column(scale=1):
37
- txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
38
- with gr.Row():
39
- gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
40
- stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
41
-
42
- def on_generate_click():
43
- return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
44
-
45
- def on_stop_click():
46
- return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
47
-
48
- gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
49
- stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
 
 
 
 
 
 
50
 
51
  with gr.Row():
52
  output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
@@ -63,8 +68,159 @@ def make_me():
63
  with gr.Row():
64
  gr.HTML("")
65
 
66
- with gr.Blocks(theme=DazDin/Go_Theme) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  make_me()
68
 
69
  demo.queue(concurrency_count=100)
70
- demo.launch()
 
2
  from random import randint
3
  from all_models import models
4
 
5
+ models_load = {}
6
+ def load_models():
7
  global models_load
 
8
  for model in models:
9
+ try:
10
+ models_load[model] = gr.Interface.load(f'models/{model}')
11
+ except Exception as error:
12
+ print(f"Failed to load model {model}: {error}")
13
+ models_load[model] = gr.Interface(lambda txt: None, ['text'], ['image'])
 
14
 
15
+ load_models()
16
 
17
  num_models = len(models)
18
  default_models = models[:num_models]
 
27
  def gen_fn(model_str, prompt):
28
  if model_str == 'NA':
29
  return None
30
+ noise = str(randint(0, 99999999))
31
+ return models_load[model_str](f'{prompt} {noise}').outputs[0]
32
 
33
  def make_me():
34
  with gr.Row():
35
+ txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
36
+ gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
37
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
38
+
39
+ def on_generate_click():
40
+ nonlocal gen_button, stop_button
41
+ gen_button.interactive = True
42
+ stop_button.interactive = True
43
+ gen_button.label = 'Generating...'
44
+ stop_button.label = 'Stop'
45
+
46
+ def on_stop_click():
47
+ nonlocal gen_button, stop_button
48
+ gen_button.interactive = False
49
+ stop_button.interactive = False
50
+ gen_button.label = 'Generate images'
51
+ stop_button.label = 'Stopped'
52
+
53
+ gen_button.click(on_generate_click, inputs=None, outputs=None)
54
+ stop_button.click(on_stop_click, inputs=None, outputs=None)
55
 
56
  with gr.Row():
57
  output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
 
68
  with gr.Row():
69
  gr.HTML("")
70
 
71
+ custom_css = """
72
+ :root {
73
+ --body-background-fill: #2d3d4f;
74
+ }
75
+ body {
76
+ background-color: var(--body-background-fill) !important;
77
+ color: #c5c6c7;
78
+ margin: 0;
79
+ padding: 0;
80
+ font-family: Arial, sans-serif;
81
+ height: 100vh;
82
+ overflow-y: auto;
83
+ }
84
+ .gradio-container {
85
+ background-color: #2d3d4f;
86
+ color: #c5c6c7;
87
+ padding: 20px;
88
+ border-radius: 8px;
89
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
90
+ width: 100%;
91
+ max-width: 1200px;
92
+ margin: 20px auto;
93
+ display: block;
94
+ min-height: 100vh;
95
+ }
96
+ .app_title {
97
+ background-color: #2d3d4f;
98
+ color: #c5c6c7;
99
+ padding: 10px 20px;
100
+ border-bottom: 1px solid #3b4252;
101
+ text-align: center;
102
+ font-size: 24px;
103
+ font-weight: bold;
104
+ width: 100%;
105
+ box-sizing: border-box;
106
+ margin-bottom: 20px;
107
+ }
108
+ .custom_textbox {
109
+ background-color: #2d343f;
110
+ border: 1px solid #3b4252;
111
+ color: #7f8184;
112
+ padding: 10px;
113
+ border-radius: 4px;
114
+ margin-bottom: 10px;
115
+ width: 100%;
116
+ box-sizing: border-box;
117
+ }
118
+ .custom_gen_button {
119
+ background-color: #8b38ff;
120
+ border: 1px solid #ffffff;
121
+ color: blue;
122
+ padding: 15px 32px;
123
+ text-align: center;
124
+ text-decoration: none;
125
+ display: inline-block;
126
+ font-size: 16px;
127
+ margin: 4px 2px;
128
+ cursor: pointer;
129
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
130
+ transition: transform 0.2s, box-shadow 0.2s;
131
+ border-radius: 4px;
132
+ }
133
+ .custom_gen_button:hover {
134
+ transform: translateY(-2px);
135
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
136
+ }
137
+ .custom_stop_button {
138
+ background-color: #6200ea;
139
+ border: 1px solid #ffffff;
140
+ color: blue;
141
+ padding: 15px 32px;
142
+ text-align: center;
143
+ text-decoration: none;
144
+ display: inline-block;
145
+ font-size: 16px;
146
+ margin: 4px 2px;
147
+ cursor: pointer;
148
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
149
+ transition: transform 0.2s, box-shadow 0.2s;
150
+ border-radius: 4px;
151
+ }
152
+ .custom_stop_button:hover {
153
+ transform: translateY(-2px);
154
+ box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
155
+ }
156
+ .custom_image {
157
+ border: 1px solid #3b4252;
158
+ background-color: #2d343f;
159
+ border-radius: 4px;
160
+ margin: 10px;
161
+ max-width: 100%;
162
+ box-sizing: border-box;
163
+ }
164
+ .custom_accordion {
165
+ background-color: #2d3d4f;
166
+ color: #7f8184;
167
+ border: 1px solid #3b4252;
168
+ border-radius: 4px;
169
+ margin-top: 20px;
170
+ width: 100%;
171
+ box-sizing: border-box;
172
+ transition: margin 0.2s ease;
173
+ }
174
+ .custom_accordion .gr-accordion-header {
175
+ background-color: #2d3d4f;
176
+ color: #7f8184;
177
+ padding: 10px 20px;
178
+ border-bottom: 1px solid #5b6270;
179
+ cursor: pointer;
180
+ font-size: 18px;
181
+ font-weight: bold;
182
+ height: 40px;
183
+ display: flex;
184
+ align-items: center;
185
+ }
186
+ .custom_accordion .gr-accordion-header:hover {
187
+ background-color: #2d3d4f;
188
+ }
189
+ .custom_accordion .gr-accordion-content {
190
+ padding: 10px 20px;
191
+ background-color: #2d3d4f;
192
+ border-top: 1px solid #5b6270;
193
+ max-height: 0;
194
+ overflow: hidden;
195
+ transition: max-height 0.2s ease;
196
+ }
197
+ .custom_accordion .gr-accordion-content.open {
198
+ max-height: 500px;
199
+ }
200
+ .custom_checkbox_group {
201
+ background-color: #2d343f;
202
+ border: 1px solid #3b4252;
203
+ color: #7f8184;
204
+ border-radius: 4px;
205
+ padding: 10px;
206
+ width: 100%;
207
+ box-sizing: border-box;
208
+ }
209
+ @media (max-width: 768px) {
210
+ .gradio-container {
211
+ width: 100%;
212
+ margin: 0;
213
+ padding: 10px;
214
+ }
215
+ .custom_textbox,.custom_image,.custom_checkbox_group {
216
+ width: 100%;
217
+ box-sizing: border-box;
218
+ }
219
+ }
220
+ """
221
+
222
+ with gr.Blocks(css=custom_css) as demo:
223
  make_me()
224
 
225
  demo.queue(concurrency_count=100)
226
+ demo.launch()