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