DazDin commited on
Commit
fa23dbc
·
verified ·
1 Parent(s): 3ebbbd1
Files changed (1) hide show
  1. app.py +21 -168
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,159 +67,8 @@ def make_me():
63
  with gr.Row():
64
  gr.HTML("")
65
 
66
- custom_css = """
67
- :root {
68
- --body-background-fill: #2d3d4f;
69
- }
70
- body {
71
- background-color: var(--body-background-fill) !important;
72
- color: #2d3d4f;
73
- margin: 0;
74
- padding: 0;
75
- font-family: Arial, sans-serif;
76
- height: 100vh;
77
- overflow-y: auto;
78
- }
79
- .gradio-container {
80
- background-color: #2d3d4f;
81
- color: #c5c6c7;
82
- padding: 20px;
83
- border-radius: 8px;
84
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
85
- width: 100%;
86
- max-width: 1200px;
87
- margin: 20px auto;
88
- display: block;
89
- min-height: 100vh;
90
- }
91
- .app_title {
92
- background-color: #2d3d4f;
93
- color: #c5c6c7;
94
- padding: 10px 20px;
95
- border-bottom: 1px solid #3b4252;
96
- text-align: center;
97
- font-size: 24px;
98
- font-weight: bold;
99
- width: 100%;
100
- box-sizing: border-box;
101
- margin-bottom: 20px;
102
- }
103
- .custom_textbox {
104
- background-color: #2d343f;
105
- border: 1px solid #3b4252;
106
- color: #7f8184;
107
- padding: 10px;
108
- border-radius: 4px;
109
- margin-bottom: 10px;
110
- width: 100%;
111
- box-sizing: border-box;
112
- }
113
- .custom_gen_button {
114
- background-color: #8b38ff;
115
- border: 1px solid #ffffff;
116
- color: blue;
117
- padding: 15px 32px;
118
- text-align: center;
119
- text-decoration: none;
120
- display: inline-block;
121
- font-size: 16px;
122
- margin: 4px 2px;
123
- cursor: pointer;
124
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
125
- transition: transform 0.2s, box-shadow 0.2s;
126
- border-radius: 4px;
127
- }
128
- .custom_gen_button:hover {
129
- transform: translateY(-2px);
130
- box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
131
- }
132
- .custom_stop_button {
133
- background-color: #6200ea;
134
- border: 1px solid #ffffff;
135
- color: blue;
136
- padding: 15px 32px;
137
- text-align: center;
138
- text-decoration: none;
139
- display: inline-block;
140
- font-size: 16px;
141
- margin: 4px 2px;
142
- cursor: pointer;
143
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
144
- transition: transform 0.2s, box-shadow 0.2s;
145
- border-radius: 4px;
146
- }
147
- .custom_stop_button:hover {
148
- transform: translateY(-2px);
149
- box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
150
- }
151
- .custom_image {
152
- border: 1px solid #3b4252;
153
- background-color: #2d343f;
154
- border-radius: 4px;
155
- margin: 10px;
156
- max-width: 100%;
157
- box-sizing: border-box;
158
- }
159
- .custom_accordion {
160
- background-color: #2d3d4f;
161
- color: #7f8184;
162
- border: 1px solid #3b4252;
163
- border-radius: 4px;
164
- margin-top: 20px;
165
- width: 100%;
166
- box-sizing: border-box;
167
- transition: margin 0.2s ease;
168
- }
169
- .custom_accordion .gr-accordion-header {
170
- background-color: #2d3d4f;
171
- color: #7f8184;
172
- padding: 10px 20px;
173
- border-bottom: 1px solid #5b6270;
174
- cursor: pointer;
175
- font-size: 18px;
176
- font-weight: bold;
177
- height: 40px;
178
- display: flex;
179
- align-items: center;
180
- }
181
- .custom_accordion .gr-accordion-header:hover {
182
- background-color: #2d3d4f;
183
- }
184
- .custom_accordion .gr-accordion-content {
185
- padding: 10px 20px;
186
- background-color: #2d3d4f;
187
- border-top: 1px solid #5b6270;
188
- max-height: 0;
189
- overflow: hidden;
190
- transition: max-height 0.2s ease;
191
- }
192
- .custom_accordion .gr-accordion-content.open {
193
- max-height: 500px;
194
- }
195
- .custom_checkbox_group {
196
- background-color: #2d343f;
197
- border: 1px solid #3b4252;
198
- color: #7f8184;
199
- border-radius: 4px;
200
- padding: 10px;
201
- width: 100%;
202
- box-sizing: border-box;
203
- }
204
- @media (max-width: 768px) {
205
- .gradio-container {
206
- width: 100%;
207
- margin: 0;
208
- padding: 10px;
209
- }
210
- .custom_textbox,.custom_image,.custom_checkbox_group {
211
- width: 100%;
212
- box-sizing: border-box;
213
- }
214
- }
215
- """
216
-
217
- with gr.Blocks(css=custom_css) as demo:
218
  make_me()
219
 
220
- demo.queue(concurrency_count=100)
221
  demo.launch()
 
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)
74
  demo.launch()