ParahumanSkitter
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
from datetime import datetime
|
|
|
|
|
5 |
|
6 |
def get_current_time():
|
7 |
now = datetime.now()
|
@@ -16,7 +18,10 @@ def load_fn(models):
|
|
16 |
for model in models:
|
17 |
if model not in models_load.keys():
|
18 |
try:
|
19 |
-
|
|
|
|
|
|
|
20 |
except Exception as error:
|
21 |
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
22 |
models_load.update({model: m})
|
@@ -67,10 +72,7 @@ def img_to_img_fn(model_str, image, prompt, negative_prompt, max_retries=10):
|
|
67 |
while retries < max_retries:
|
68 |
try:
|
69 |
noise = str(randint(0, 9999999))
|
70 |
-
|
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
|
@@ -148,6 +150,154 @@ def make_image_to_image():
|
|
148 |
|
149 |
custom_css = """
|
150 |
/* Your existing CSS styles here */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
"""
|
152 |
|
153 |
with gr.Blocks(css=custom_css) as demo:
|
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
from datetime import datetime
|
5 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
6 |
+
import torch
|
7 |
|
8 |
def get_current_time():
|
9 |
now = datetime.now()
|
|
|
18 |
for model in models:
|
19 |
if model not in models_load.keys():
|
20 |
try:
|
21 |
+
if 'img2img' in model.lower(): # Assuming models with 'img2img' in their name are image-to-image models
|
22 |
+
m = StableDiffusionImg2ImgPipeline.from_pretrained(f'models/{model}')
|
23 |
+
else:
|
24 |
+
m = gr.load(f'models/{model}')
|
25 |
except Exception as error:
|
26 |
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
27 |
models_load.update({model: m})
|
|
|
72 |
while retries < max_retries:
|
73 |
try:
|
74 |
noise = str(randint(0, 9999999))
|
75 |
+
result = models_load[model_str](prompt=f'{prompt} {noise}', negative_prompt=negative_prompt, image=image).images[0]
|
|
|
|
|
|
|
76 |
return result
|
77 |
except Exception as e:
|
78 |
# Check for specific error messages or status codes
|
|
|
150 |
|
151 |
custom_css = """
|
152 |
/* Your existing CSS styles here */
|
153 |
+
:root {
|
154 |
+
--body-background-fill: #2d3d4f;
|
155 |
+
}
|
156 |
+
body {
|
157 |
+
background-color: var(--body-background-fill) !important;
|
158 |
+
color: #2d3d4f;
|
159 |
+
margin: 0;
|
160 |
+
padding: 0;
|
161 |
+
font-family: Arial, sans-serif;
|
162 |
+
height: 100vh;
|
163 |
+
overflow-y: auto;
|
164 |
+
}
|
165 |
+
.gradio-container {
|
166 |
+
background-color: #2d3d4f;
|
167 |
+
color: #c5c6c7;
|
168 |
+
padding: 20px;
|
169 |
+
border-radius: 8px;
|
170 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
171 |
+
width: 100%;
|
172 |
+
max-width: 1200px;
|
173 |
+
margin: 20px auto;
|
174 |
+
display: block;
|
175 |
+
min-height: 100vh;
|
176 |
+
}
|
177 |
+
.app_title {
|
178 |
+
background-color: #2d3d4f;
|
179 |
+
color: #c5c6c7;
|
180 |
+
padding: 10px 20px;
|
181 |
+
border-bottom: 1px solid #3b4252;
|
182 |
+
text-align: center;
|
183 |
+
font-size: 24px;
|
184 |
+
font-weight: bold;
|
185 |
+
width: 100%;
|
186 |
+
box-sizing: border-box;
|
187 |
+
margin-bottom: 20px;
|
188 |
+
}
|
189 |
+
.custom_textbox, .custom_negative_textbox {
|
190 |
+
background-color: #2d343f;
|
191 |
+
border: 1px solid #3b4252;
|
192 |
+
color: #7f8184;
|
193 |
+
padding: 10px;
|
194 |
+
border-radius: 4px;
|
195 |
+
margin-bottom: 10px;
|
196 |
+
width: 100%;
|
197 |
+
box-sizing: border-box;
|
198 |
+
}
|
199 |
+
.custom_gen_button {
|
200 |
+
background-color: #8b38ff;
|
201 |
+
border: 1px solid #ffffff;
|
202 |
+
color: blue;
|
203 |
+
padding: 15px 32px;
|
204 |
+
text-align: center;
|
205 |
+
text-decoration: none;
|
206 |
+
display: inline-block;
|
207 |
+
font-size: 16px;
|
208 |
+
margin: 4px 2px;
|
209 |
+
cursor: pointer;
|
210 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
211 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
212 |
+
border-radius: 4px;
|
213 |
+
}
|
214 |
+
.custom_gen_button:hover {
|
215 |
+
transform: translateY(-2px);
|
216 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
217 |
+
}
|
218 |
+
.custom_stop_button {
|
219 |
+
background-color: #6200ea;
|
220 |
+
border: 1px solid #ffffff;
|
221 |
+
color: blue;
|
222 |
+
padding: 15px 32px;
|
223 |
+
text-align: center;
|
224 |
+
text-decoration: none;
|
225 |
+
display: inline-block;
|
226 |
+
font-size: 16px;
|
227 |
+
margin: 4px 2px;
|
228 |
+
cursor: pointer;
|
229 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
230 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
231 |
+
border-radius: 4px;
|
232 |
+
}
|
233 |
+
.custom_stop_button:hover {
|
234 |
+
transform: translateY(-2px);
|
235 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
|
236 |
+
}
|
237 |
+
.custom_image {
|
238 |
+
border: 1px solid #3b4252;
|
239 |
+
background-color: #2d343f;
|
240 |
+
border-radius: 4px;
|
241 |
+
margin: 10px;
|
242 |
+
max-width: 100%;
|
243 |
+
box-sizing: border-box;
|
244 |
+
}
|
245 |
+
.custom_accordion {
|
246 |
+
background-color: #2d3d4f;
|
247 |
+
color: #7f8184;
|
248 |
+
border: 1px solid #3b4252;
|
249 |
+
border-radius: 4px;
|
250 |
+
margin-top: 20px;
|
251 |
+
width: 100%;
|
252 |
+
box-sizing: border-box;
|
253 |
+
transition: margin 0.2s ease;
|
254 |
+
}
|
255 |
+
.custom_accordion .gr-accordion-header {
|
256 |
+
background-color: #2d3d4f;
|
257 |
+
color: #7f8184;
|
258 |
+
padding: 10px 20px;
|
259 |
+
border-bottom: 1px solid #5b6270;
|
260 |
+
cursor: pointer;
|
261 |
+
font-size: 18px;
|
262 |
+
font-weight: bold;
|
263 |
+
height: 40px;
|
264 |
+
display: flex;
|
265 |
+
align-items: center;
|
266 |
+
}
|
267 |
+
.custom_accordion .gr-accordion-header:hover {
|
268 |
+
background-color: #2d3d4f;
|
269 |
+
}
|
270 |
+
.custom_accordion .gr-accordion-content {
|
271 |
+
padding: 10px 20px;
|
272 |
+
background-color: #2d3d4f;
|
273 |
+
border-top: 1px solid #5b6270;
|
274 |
+
max-height: 0;
|
275 |
+
overflow: hidden;
|
276 |
+
transition: max-height 0.2s ease;
|
277 |
+
}
|
278 |
+
.custom_accordion .gr-accordion-content.open {
|
279 |
+
max-height: 500px;
|
280 |
+
}
|
281 |
+
.custom_checkbox_group {
|
282 |
+
background-color: #2d343f;
|
283 |
+
border: 1px solid #3b4252;
|
284 |
+
color: #7f8184;
|
285 |
+
border-radius: 4px;
|
286 |
+
padding: 10px;
|
287 |
+
width: 100%;
|
288 |
+
box-sizing: border-box;
|
289 |
+
}
|
290 |
+
@media (max-width: 768px) {
|
291 |
+
.gradio-container {
|
292 |
+
width: 100%;
|
293 |
+
margin: 0;
|
294 |
+
padding: 10px;
|
295 |
+
}
|
296 |
+
.custom_textbox, .custom_negative_textbox, .custom_image, .custom_checkbox_group {
|
297 |
+
width: 100%;
|
298 |
+
box-sizing: border-box;
|
299 |
+
}
|
300 |
+
}
|
301 |
"""
|
302 |
|
303 |
with gr.Blocks(css=custom_css) as demo:
|