Spaces:
Runtime error
Runtime error
Commit
·
9f2724b
1
Parent(s):
8811dd9
Update app.py
Browse files
app.py
CHANGED
@@ -92,14 +92,7 @@ def get_EOS_pos_in_prompt(prompt):
|
|
92 |
|
93 |
|
94 |
import torch.nn.functional as F
|
95 |
-
|
96 |
-
def gradient_loss(images):
|
97 |
-
# Compute gradient magnitude using Sobel filters.
|
98 |
-
gradient_x = F.conv2d(images, torch.Tensor([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]).view(1, 1, 3, 3).to(images.device))
|
99 |
-
gradient_y = F.conv2d(images, torch.Tensor([[-1, -2, -1], [0, 0, 0], [1, 2, 1]]).view(1, 1, 3, 3).to(images.device))
|
100 |
-
gradient_magnitude = torch.sqrt(gradient_x**2 + gradient_y**2)
|
101 |
-
return gradient_magnitude.mean()
|
102 |
-
"""
|
103 |
|
104 |
from torchvision.transforms import ToTensor
|
105 |
def pil_to_latent(input_im):
|
@@ -317,13 +310,13 @@ def image_generator(prompt="cat", loss_function=None):
|
|
317 |
images_without_loss.append(generated_img)
|
318 |
|
319 |
if loss_function:
|
320 |
-
if loss_function == "
|
321 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=exposure_loss)
|
322 |
-
elif loss_function == "
|
323 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=color_diversity_loss)
|
324 |
-
elif loss_function == "
|
325 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=sharpness_loss)
|
326 |
-
elif loss_function == "
|
327 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=brilliance_loss)
|
328 |
images_with_loss.append(generated_img)
|
329 |
|
@@ -341,12 +334,39 @@ def image_generator(prompt="cat", loss_function=None):
|
|
341 |
def image_generator_wrapper(prompt="dog", selected_loss="None"):
|
342 |
return image_generator(prompt, selected_loss)
|
343 |
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
demo = gr.Interface(image_generator_wrapper,
|
348 |
-
inputs=[gr.Textbox(label="Enter prompt for
|
349 |
-
gr.Radio(["None", "
|
350 |
outputs=gr.Plot(label="Generated Images"),
|
351 |
title=title,
|
352 |
description=description)
|
|
|
92 |
|
93 |
|
94 |
import torch.nn.functional as F
|
95 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
from torchvision.transforms import ToTensor
|
98 |
def pil_to_latent(input_im):
|
|
|
310 |
images_without_loss.append(generated_img)
|
311 |
|
312 |
if loss_function:
|
313 |
+
if loss_function == "Exposure":
|
314 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=exposure_loss)
|
315 |
+
elif loss_function == "Color Diversity":
|
316 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=color_diversity_loss)
|
317 |
+
elif loss_function == "Sharpness":
|
318 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=sharpness_loss)
|
319 |
+
elif loss_function == "Brilliance":
|
320 |
generated_img = generate_image_custom_style(prompt, style_num=i, random_seed=seed_values[i], custom_loss_fn=brilliance_loss)
|
321 |
images_with_loss.append(generated_img)
|
322 |
|
|
|
334 |
def image_generator_wrapper(prompt="dog", selected_loss="None"):
|
335 |
return image_generator(prompt, selected_loss)
|
336 |
|
337 |
+
icon_html = '<i class="fas fa-chart-bar"></i>'
|
338 |
+
title_with_icon = f"""
|
339 |
+
<div style="background-color: #f5f1f2; padding: 10px; display: flex; align-items: center;">
|
340 |
+
{icon_html} <span style="margin-left: 10px;">Image Generation using Stable Diffusion</span>
|
341 |
+
</div>
|
342 |
+
"""
|
343 |
+
description_with_icon = f"""
|
344 |
+
<div style="background-color: #f1f1f5; padding: 10px; display: flex; align-items: center;">
|
345 |
+
{icon_html}
|
346 |
+
<span style="margin-left: 10px;">
|
347 |
+
<p><strong>Embedding New Styles Into Stable Diffusion</strong></p>
|
348 |
+
<p><strong>Following are the concepts trained on</strong></p>
|
349 |
+
<ul>
|
350 |
+
<li>animal-toy</li>
|
351 |
+
<li>fft</li>
|
352 |
+
<li>midjourney</li>
|
353 |
+
<li>oil style</li>
|
354 |
+
<li>space style</li>
|
355 |
+
</ul>
|
356 |
+
<p>Following are some Losses tried</p>
|
357 |
+
<ul>
|
358 |
+
<li>exposure : It helps control the overall exposure of generated images. It ensures that the contrast of the generated images align with the desired aesthetic, preventing overexposure or underexposure</li>
|
359 |
+
<li>Brilliance: Brilliance loss is a loss function that emphasizes the brilliance or luminance of specific image components, such as highlights. It can be used to highlight or enhance certain aspects of the generated artwork, adding a touch of brilliance or radiance to the final image.</li>
|
360 |
+
<li>color diversity: Color diversity loss encourages the model to produce images with a wider range of colors and hues. It helps create visually diverse and vibrant artworks by minimizing color repetition and promoting a rich color palette in the generated images</li>
|
361 |
+
<li>sharpness: Sharpness loss is used to enhance the level of detail and clarity in generated images. It encourages the model to produce crisp and well-defined visual elements, leading to sharper and more realistic results.</li>
|
362 |
+
</ul>
|
363 |
+
</span>
|
364 |
+
</div>
|
365 |
+
"""
|
366 |
|
367 |
demo = gr.Interface(image_generator_wrapper,
|
368 |
+
inputs=[gr.Textbox(label="Enter prompt for generating Image", type="text", value="A ballerina cat dancing in space"),
|
369 |
+
gr.Radio(["None", "Exposure", "Color Diversity", "Sharpness", "Brilliance"], value="None", label="Select Loss")],
|
370 |
outputs=gr.Plot(label="Generated Images"),
|
371 |
title=title,
|
372 |
description=description)
|