ParahumanSkitter
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,33 @@ def gen_fn(model_str, prompt, negative_prompt, max_retries=10):
|
|
59 |
|
60 |
return None
|
61 |
|
62 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
with gr.Row():
|
64 |
with gr.Column(scale=1):
|
65 |
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
@@ -88,163 +114,48 @@ def make_me():
|
|
88 |
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
89 |
model_choice.change(update_imgbox, model_choice, output)
|
90 |
model_choice.change(extend_choices, model_choice, current_models)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
with gr.Row():
|
93 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
custom_css = """
|
96 |
-
|
97 |
-
--body-background-fill: #2d3d4f;
|
98 |
-
}
|
99 |
-
body {
|
100 |
-
background-color: var(--body-background-fill) !important;
|
101 |
-
color: #2d3d4f;
|
102 |
-
margin: 0;
|
103 |
-
padding: 0;
|
104 |
-
font-family: Arial, sans-serif;
|
105 |
-
height: 100vh;
|
106 |
-
overflow-y: auto;
|
107 |
-
}
|
108 |
-
.gradio-container {
|
109 |
-
background-color: #2d3d4f;
|
110 |
-
color: #c5c6c7;
|
111 |
-
padding: 20px;
|
112 |
-
border-radius: 8px;
|
113 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
114 |
-
width: 100%;
|
115 |
-
max-width: 1200px;
|
116 |
-
margin: 20px auto;
|
117 |
-
display: block;
|
118 |
-
min-height: 100vh;
|
119 |
-
}
|
120 |
-
.app_title {
|
121 |
-
background-color: #2d3d4f;
|
122 |
-
color: #c5c6c7;
|
123 |
-
padding: 10px 20px;
|
124 |
-
border-bottom: 1px solid #3b4252;
|
125 |
-
text-align: center;
|
126 |
-
font-size: 24px;
|
127 |
-
font-weight: bold;
|
128 |
-
width: 100%;
|
129 |
-
box-sizing: border-box;
|
130 |
-
margin-bottom: 20px;
|
131 |
-
}
|
132 |
-
.custom_textbox, .custom_negative_textbox {
|
133 |
-
background-color: #2d343f;
|
134 |
-
border: 1px solid #3b4252;
|
135 |
-
color: #7f8184;
|
136 |
-
padding: 10px;
|
137 |
-
border-radius: 4px;
|
138 |
-
margin-bottom: 10px;
|
139 |
-
width: 100%;
|
140 |
-
box-sizing: border-box;
|
141 |
-
}
|
142 |
-
.custom_gen_button {
|
143 |
-
background-color: #8b38ff;
|
144 |
-
border: 1px solid #ffffff;
|
145 |
-
color: blue;
|
146 |
-
padding: 15px 32px;
|
147 |
-
text-align: center;
|
148 |
-
text-decoration: none;
|
149 |
-
display: inline-block;
|
150 |
-
font-size: 16px;
|
151 |
-
margin: 4px 2px;
|
152 |
-
cursor: pointer;
|
153 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
154 |
-
transition: transform 0.2s, box-shadow 0.2s;
|
155 |
-
border-radius: 4px;
|
156 |
-
}
|
157 |
-
.custom_gen_button:hover {
|
158 |
-
transform: translateY(-2px);
|
159 |
-
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
160 |
-
}
|
161 |
-
.custom_stop_button {
|
162 |
-
background-color: #6200ea;
|
163 |
-
border: 1px solid #ffffff;
|
164 |
-
color: blue;
|
165 |
-
padding: 15px 32px;
|
166 |
-
text-align: center;
|
167 |
-
text-decoration: none;
|
168 |
-
display: inline-block;
|
169 |
-
font-size: 16px;
|
170 |
-
margin: 4px 2px;
|
171 |
-
cursor: pointer;
|
172 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
173 |
-
transition: transform 0.2s, box-shadow 0.2s;
|
174 |
-
border-radius: 4px;
|
175 |
-
}
|
176 |
-
.custom_stop_button:hover {
|
177 |
-
transform: translateY(-2px);
|
178 |
-
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
179 |
-
}
|
180 |
-
.custom_image {
|
181 |
-
border: 1px solid #3b4252;
|
182 |
-
background-color: #2d343f;
|
183 |
-
border-radius: 4px;
|
184 |
-
margin: 10px;
|
185 |
-
max-width: 100%;
|
186 |
-
box-sizing: border-box;
|
187 |
-
}
|
188 |
-
.custom_accordion {
|
189 |
-
background-color: #2d3d4f;
|
190 |
-
color: #7f8184;
|
191 |
-
border: 1px solid #3b4252;
|
192 |
-
border-radius: 4px;
|
193 |
-
margin-top: 20px;
|
194 |
-
width: 100%;
|
195 |
-
box-sizing: border-box;
|
196 |
-
transition: margin 0.2s ease;
|
197 |
-
}
|
198 |
-
.custom_accordion .gr-accordion-header {
|
199 |
-
background-color: #2d3d4f;
|
200 |
-
color: #7f8184;
|
201 |
-
padding: 10px 20px;
|
202 |
-
border-bottom: 1px solid #5b6270;
|
203 |
-
cursor: pointer;
|
204 |
-
font-size: 18px;
|
205 |
-
font-weight: bold;
|
206 |
-
height: 40px;
|
207 |
-
display: flex;
|
208 |
-
align-items: center;
|
209 |
-
}
|
210 |
-
.custom_accordion .gr-accordion-header:hover {
|
211 |
-
background-color: #2d3d4f;
|
212 |
-
}
|
213 |
-
.custom_accordion .gr-accordion-content {
|
214 |
-
padding: 10px 20px;
|
215 |
-
background-color: #2d3d4f;
|
216 |
-
border-top: 1px solid #5b6270;
|
217 |
-
max-height: 0;
|
218 |
-
overflow: hidden;
|
219 |
-
transition: max-height 0.2s ease;
|
220 |
-
}
|
221 |
-
.custom_accordion .gr-accordion-content.open {
|
222 |
-
max-height: 500px;
|
223 |
-
}
|
224 |
-
.custom_checkbox_group {
|
225 |
-
background-color: #2d343f;
|
226 |
-
border: 1px solid #3b4252;
|
227 |
-
color: #7f8184;
|
228 |
-
border-radius: 4px;
|
229 |
-
padding: 10px;
|
230 |
-
width: 100%;
|
231 |
-
box-sizing: border-box;
|
232 |
-
}
|
233 |
-
@media (max-width: 768px) {
|
234 |
-
.gradio-container {
|
235 |
-
width: 100%;
|
236 |
-
margin: 0;
|
237 |
-
padding: 10px;
|
238 |
-
}
|
239 |
-
.custom_textbox, .custom_negative_textbox, .custom_image, .custom_checkbox_group {
|
240 |
-
width: 100%;
|
241 |
-
box-sizing: border-box;
|
242 |
-
}
|
243 |
-
}
|
244 |
"""
|
245 |
|
246 |
-
with gr.Blocks(css=custom_css) as demo:
|
247 |
-
|
|
|
|
|
|
|
|
|
248 |
|
249 |
demo.queue(concurrency_count=500)
|
250 |
demo.launch()
|
|
|
59 |
|
60 |
return None
|
61 |
|
62 |
+
def img_to_img_fn(model_str, image, prompt, negative_prompt, max_retries=10):
|
63 |
+
if model_str == 'NA' or image is None:
|
64 |
+
return None
|
65 |
+
|
66 |
+
retries = 0
|
67 |
+
while retries < max_retries:
|
68 |
+
try:
|
69 |
+
noise = str(randint(0, 9999999))
|
70 |
+
if hasattr(models_load[model_str], 'negative_prompt'):
|
71 |
+
result = models_load[model_str](image, prompt=f'{prompt} {noise}', negative_prompt=negative_prompt)
|
72 |
+
else:
|
73 |
+
result = models_load[model_str](image, prompt=f'{prompt} {noise}')
|
74 |
+
return result
|
75 |
+
except Exception as e:
|
76 |
+
# Check for specific error messages or status codes
|
77 |
+
if "CUDA out of memory" in str(e) or "500" in str(e):
|
78 |
+
print(f"CUDA out of memory or server error: {e}")
|
79 |
+
else:
|
80 |
+
print(f"Error generating image: {e}")
|
81 |
+
|
82 |
+
retries += 1
|
83 |
+
if retries >= max_retries:
|
84 |
+
raise Exception(f"Failed to generate image after {max_retries} retries.")
|
85 |
+
|
86 |
+
return None
|
87 |
+
|
88 |
+
def make_text_to_image():
|
89 |
with gr.Row():
|
90 |
with gr.Column(scale=1):
|
91 |
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
|
|
114 |
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
115 |
model_choice.change(update_imgbox, model_choice, output)
|
116 |
model_choice.change(extend_choices, model_choice, current_models)
|
117 |
+
|
118 |
+
def make_image_to_image():
|
119 |
+
with gr.Row():
|
120 |
+
with gr.Column(scale=1):
|
121 |
+
img_input = gr.Image(label='Input Image', type='pil')
|
122 |
+
txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
|
123 |
+
negative_txt_input = gr.Textbox(label='Negative prompt:', lines=3, container=False, elem_id="custom_negative_textbox", placeholder="Negative Prompt")
|
124 |
+
with gr.Row():
|
125 |
+
gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
|
126 |
+
stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
127 |
+
|
128 |
+
def on_generate_click():
|
129 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
|
130 |
+
|
131 |
+
def on_stop_click():
|
132 |
+
return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
|
133 |
+
|
134 |
+
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
135 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
136 |
|
137 |
with gr.Row():
|
138 |
+
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
139 |
+
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
140 |
+
for m, o in zip(current_models, output):
|
141 |
+
gen_event = gen_button.click(img_to_img_fn, [m, img_input, txt_input, negative_txt_input], o)
|
142 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
143 |
+
|
144 |
+
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
145 |
+
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
146 |
+
model_choice.change(update_imgbox, model_choice, output)
|
147 |
+
model_choice.change(extend_choices, model_choice, current_models)
|
148 |
|
149 |
custom_css = """
|
150 |
+
/* Your existing CSS styles here */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
"""
|
152 |
|
153 |
+
with gr.Blocks(css=custom_css) as demo:
|
154 |
+
with gr.Tabs():
|
155 |
+
with gr.TabItem("Text-to-Image"):
|
156 |
+
make_text_to_image()
|
157 |
+
with gr.TabItem("Image-to-Image"):
|
158 |
+
make_image_to_image()
|
159 |
|
160 |
demo.queue(concurrency_count=500)
|
161 |
demo.launch()
|