DazDin commited on
Commit
04af459
·
verified ·
1 Parent(s): 6ef603a
Files changed (1) hide show
  1. app.py +20 -180
app.py CHANGED
@@ -1,7 +1,10 @@
 
1
  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 = {}
@@ -28,28 +31,29 @@ 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]
53
  current_models = [gr.Textbox(m, visible=False) for m in default_models]
54
  for m, o in zip(current_models, output):
55
  gen_event = gen_button.click(gen_fn, [m, txt_input], o)
@@ -63,171 +67,7 @@ def make_me():
63
  with gr.Row():
64
  gr.HTML("")
65
 
66
- custom_css = """
67
- :root {
68
- --body-background-fill: #2d3d4f;
69
- }
70
-
71
- body {
72
- background-color: var(--body-background-fill) !important;
73
- color: #2d3d4f;
74
- margin: 0;
75
- padding: 0;
76
- font-family: Arial, sans-serif;
77
- height: 100vh;
78
- overflow-y: auto;
79
- }
80
-
81
- .gradio-container {
82
- background-color: #2d3d4f;
83
- color: #c5c6c7;
84
- padding: 20px;
85
- border-radius: 8px;
86
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
87
- width: 100%;
88
- max-width: 1200px;
89
- margin: 20px auto;
90
- display: block;
91
- min-height: 100vh;
92
- }
93
-
94
- .app_title {
95
- background-color: #2d3d4f;
96
- color: #c5c6c7;
97
- padding: 10px 20px;
98
- border-bottom: 1px solid #3b4252;
99
- text-align: center;
100
- font-size: 24px;
101
- font-weight: bold;
102
- width: 100%;
103
- box-sizing: border-box;
104
- margin-bottom: 20px;
105
- }
106
-
107
- .custom_textbox {
108
- background-color: #2d343f;
109
- border: 1px solid #3b4252;
110
- color: #7f8184;
111
- padding: 10px;
112
- border-radius: 4px;
113
- margin-bottom: 10px;
114
- width: 100%;
115
- box-sizing: border-box;
116
- }
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
-
157
- .custom_image {
158
- border: 1px solid #3b4252;
159
- background-color: #2d343f;
160
- border-radius: 4px;
161
- margin: 10px;
162
- max-width: 100%;
163
- box-sizing: border-box;
164
- }
165
-
166
- .custom_accordion {
167
- background-color: #2d3d4f;
168
- color: #7f8184;
169
- border: 1px solid #3b4252;
170
- border-radius: 4px;
171
- margin-top: 20px;
172
- width: 100%;
173
- box-sizing: border-box;
174
- transition: margin 0.2s ease;
175
- }
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
-
190
- .custom_accordion .gr-accordion-header:hover {
191
- background-color: #2d3d4f;
192
- }
193
-
194
- .custom_accordion .gr-accordion-content {
195
- padding: 10px 20px;
196
- background-color: #2d3d4f;
197
- border-top: 1px solid #5b6270;
198
- max-height: 0;
199
- overflow: hidden;
200
- transition: max-height 0.2s ease;
201
- }
202
-
203
- .custom_accordion .gr-accordion-content.open {
204
- max-height: 500px;
205
- }
206
-
207
- .custom_checkbox_group {
208
- background-color: #2d343f;
209
- border: 1px solid #3b4252;
210
- color: #7f8184;
211
- border-radius: 4px;
212
- padding: 10px;
213
- width: 100%;
214
- box-sizing: border-box;
215
- }
216
-
217
- @media (max-width: 768px) {
218
- .gradio-container {
219
- width: 100%;
220
- margin: 0;
221
- padding: 10px;
222
- }
223
- .custom_textbox,.custom_image,.custom_checkbox_group {
224
- width: 100%;
225
- box-sizing: border-box;
226
- }
227
- }
228
- """
229
-
230
- with gr.Blocks(css=custom_css) as demo:
231
  make_me()
232
 
233
  demo.queue(concurrency_count=50)
 
1
+ import os
2
  import gradio as gr
3
  from random import randint
4
  from all_models import models
5
 
6
+ css_code = os.getenv("DazDinGo_CSS", "No CSS found")
7
+
8
  def load_fn(models):
9
  global models_load
10
  models_load = {}
 
31
  def gen_fn(model_str, prompt):
32
  if model_str == 'NA':
33
  return None
34
+ noise = str(randint(0, 99999999))
35
  return models_load[model_str](f'{prompt} {noise}')
36
 
37
  def make_me():
38
  with gr.Row():
39
+ with gr.Column(scale=4):
40
+ txt_input = gr.Textbox(label='Your prompt:', lines=4, container=False, elem_id="custom_textbox", placeholder="Prompt", height=250)
41
+
42
  with gr.Column(scale=1):
43
+ gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
44
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
45
+
46
+ def on_generate_click():
47
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
48
+
49
+ def on_stop_click():
50
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
51
+
52
+ gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
53
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
 
 
54
 
55
  with gr.Row():
56
+ output = [gr.Image(label=m, width=512, max_height=768, elem_id="custom_image", show_label=True, interactive=False, show_share_button=False) for m in default_models]
57
  current_models = [gr.Textbox(m, visible=False) for m in default_models]
58
  for m, o in zip(current_models, output):
59
  gen_event = gen_button.click(gen_fn, [m, txt_input], o)
 
67
  with gr.Row():
68
  gr.HTML("")
69
 
70
+ with gr.Blocks(css=css_code) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  make_me()
72
 
73
  demo.queue(concurrency_count=50)