Spaces:
Runtime error
Runtime error
Commit
·
9ff8d1e
1
Parent(s):
b1929d0
Update app.py
Browse files
app.py
CHANGED
|
@@ -300,39 +300,35 @@ def display_images_in_rows(images_with_titles, titles):
|
|
| 300 |
return fig
|
| 301 |
# plt.show()
|
| 302 |
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
images_without_loss.append(generated_img)
|
| 311 |
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 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 |
|
| 323 |
-
|
| 324 |
-
titles = ["animal toy", "fft style", "mid journey", "oil style", "Space style"]
|
| 325 |
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
| 330 |
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
# Create a wrapper function for image_generator()
|
| 334 |
-
def image_generator_wrapper(prompt="cat", loss_function=None):
|
| 335 |
-
return image_generator(prompt, loss_function)
|
| 336 |
|
| 337 |
icon_html = '<i class="fas fa-chart-bar"></i>'
|
| 338 |
title = f"""
|
|
@@ -345,21 +341,12 @@ description = f"""
|
|
| 345 |
{icon_html}
|
| 346 |
<span style="margin-left: 10px;">
|
| 347 |
<p><strong>Embedding New Styles Into Stable Diffusion</strong></p>
|
| 348 |
-
<p>Following are some Losses tried</p>
|
| 349 |
-
<ul>
|
| 350 |
-
<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>
|
| 351 |
-
<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>
|
| 352 |
-
<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>
|
| 353 |
-
<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>
|
| 354 |
-
</ul>
|
| 355 |
</span>
|
| 356 |
</div>
|
| 357 |
"""
|
| 358 |
|
| 359 |
demo = gr.Interface(image_generator_wrapper,
|
| 360 |
-
inputs=[gr.Textbox(label="Enter prompt for
|
| 361 |
-
gr.Radio(["
|
| 362 |
-
outputs=gr.Plot(label="Generated Images"),
|
| 363 |
-
title=title,
|
| 364 |
-
description=description)
|
| 365 |
demo.launch()
|
|
|
|
| 300 |
return fig
|
| 301 |
# plt.show()
|
| 302 |
|
| 303 |
+
def image_generator(prompt = "dog", loss_function=None):
|
| 304 |
+
images_without_loss = []
|
| 305 |
+
images_with_loss = []
|
| 306 |
|
| 307 |
+
for i in range(num_styles):
|
| 308 |
+
generated_img = generate_image_custom_style(prompt,style_num = i,random_seed = seed_values[i],custom_loss_fn = None)
|
| 309 |
+
images_without_loss.append(generated_img)
|
| 310 |
+
if loss_function:
|
| 311 |
+
generated_img = generate_image_custom_style(prompt,style_num = i,random_seed = seed_values[i],custom_loss_fn = loss_function)
|
| 312 |
+
images_with_loss.append(generated_img)
|
| 313 |
|
| 314 |
+
generated_sd_images = []
|
| 315 |
+
titles = ["animal toy", "fft style", "mid journey", "oil style", "Space style"]
|
|
|
|
| 316 |
|
| 317 |
+
for i in range(len(titles)):
|
| 318 |
+
generated_sd_images.append((images_without_loss[i], titles[i]))
|
| 319 |
+
if images_with_loss != []:
|
| 320 |
+
generated_sd_images.append((images_with_loss[i], titles[i]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
+
return display_images_in_rows(generated_sd_images, titles)
|
|
|
|
| 323 |
|
| 324 |
+
# Create a wrapper function for show_misclassified_images()
|
| 325 |
+
def image_generator_wrapper(prompt = "dog", loss_function=None):
|
| 326 |
+
if loss_function == "Yes":
|
| 327 |
+
loss_function = color_diversity_loss
|
| 328 |
+
else:
|
| 329 |
+
loss_function = None
|
| 330 |
|
| 331 |
+
return image_generator(prompt, loss_function)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
|
| 333 |
icon_html = '<i class="fas fa-chart-bar"></i>'
|
| 334 |
title = f"""
|
|
|
|
| 341 |
{icon_html}
|
| 342 |
<span style="margin-left: 10px;">
|
| 343 |
<p><strong>Embedding New Styles Into Stable Diffusion</strong></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
</span>
|
| 345 |
</div>
|
| 346 |
"""
|
| 347 |
|
| 348 |
demo = gr.Interface(image_generator_wrapper,
|
| 349 |
+
inputs=[gr.Textbox(label="Enter prompt for generation", type="text", value="A ballerina cat dancing in space"),
|
| 350 |
+
gr.Radio(["Yes", "No"], value="No" , label="Apply color diversity Loss")],
|
| 351 |
+
outputs=gr.Plot(label="Generated Images"), title = title, description=description)
|
|
|
|
|
|
|
| 352 |
demo.launch()
|