Spaces:
Runtime error
Runtime error
code update
Browse files
app.py
CHANGED
@@ -42,11 +42,13 @@ style_files = ['stable_diffusion/learned_embeddings/arcane-style-jv.bin', 'stabl
|
|
42 |
'stable_diffusion/learned_embeddings/dr-strange.bin', 'stable_diffusion/learned_embeddings/midjourney-style.bin',
|
43 |
'stable_diffusion/learned_embeddings/oil_style.bin']
|
44 |
|
|
|
|
|
45 |
|
46 |
seed_values = [8,16,50,80,128]
|
47 |
height = 512 # default height of Stable Diffusion
|
48 |
width = 512 # default width of Stable Diffusion
|
49 |
-
num_inference_steps =
|
50 |
guidance_scale = 7.5 # Scale for classifier-free guidance
|
51 |
num_styles = len(style_files)
|
52 |
|
@@ -80,7 +82,6 @@ def get_output_embeds(input_embeddings):
|
|
80 |
# And now they're ready!
|
81 |
return output
|
82 |
|
83 |
-
|
84 |
def get_style_embeddings(style_file):
|
85 |
style_embed = torch.load(style_file)
|
86 |
style_name = list(style_embed.keys())[0]
|
@@ -247,55 +248,48 @@ def display_images_in_rows(images_with_titles, titles):
|
|
247 |
axes[r, c].axis('off')
|
248 |
|
249 |
return fig
|
|
|
|
|
250 |
|
251 |
def image_generator(prompt = "dog", loss_function=None):
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
height = 512 # default height of Stable Diffusion
|
263 |
-
width = 512 # default width of Stable Diffusion
|
264 |
-
num_inference_steps = 1 # Number of denoising steps
|
265 |
-
guidance_scale = 7.5 # Scale for classifier-free guidance
|
266 |
-
num_styles = len(style_files)
|
267 |
-
|
268 |
-
for i in range(num_styles):
|
269 |
-
this_generated_img_1 = generate_images(prompt,style_num = i,random_seed = seed_values[i],custom_loss_fn = None)
|
270 |
-
images_without_loss.append(this_generated_img_1)
|
271 |
if loss_function:
|
272 |
-
|
273 |
-
images_with_loss.append(
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
return display_images_in_rows(generated_sd_images, titles)
|
284 |
|
|
|
285 |
|
286 |
# Create a wrapper function for show_misclassified_images()
|
287 |
def image_generator_wrapper(prompt = "dog", loss_function=None):
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
|
293 |
-
|
294 |
|
295 |
-
description = "Generate an image with a prompt and apply loss if you wish to"
|
296 |
|
297 |
demo = gr.Interface(image_generator,
|
298 |
-
inputs=[gr.Textbox(label="Enter prompt for
|
299 |
gr.Radio(["Yes", "No"], value="No" , label="Apply vibrance loss")],
|
300 |
-
outputs=gr.Plot(label="
|
301 |
-
demo.launch()
|
|
|
42 |
'stable_diffusion/learned_embeddings/dr-strange.bin', 'stable_diffusion/learned_embeddings/midjourney-style.bin',
|
43 |
'stable_diffusion/learned_embeddings/oil_style.bin']
|
44 |
|
45 |
+
images_without_loss = []
|
46 |
+
images_with_loss = []
|
47 |
|
48 |
seed_values = [8,16,50,80,128]
|
49 |
height = 512 # default height of Stable Diffusion
|
50 |
width = 512 # default width of Stable Diffusion
|
51 |
+
num_inference_steps = 10 # Number of denoising steps
|
52 |
guidance_scale = 7.5 # Scale for classifier-free guidance
|
53 |
num_styles = len(style_files)
|
54 |
|
|
|
82 |
# And now they're ready!
|
83 |
return output
|
84 |
|
|
|
85 |
def get_style_embeddings(style_file):
|
86 |
style_embed = torch.load(style_file)
|
87 |
style_name = list(style_embed.keys())[0]
|
|
|
248 |
axes[r, c].axis('off')
|
249 |
|
250 |
return fig
|
251 |
+
# plt.show()
|
252 |
+
|
253 |
|
254 |
def image_generator(prompt = "dog", loss_function=None):
|
255 |
+
images_without_loss = []
|
256 |
+
images_with_loss = []
|
257 |
+
if loss_function == "Yes":
|
258 |
+
loss_function = vibrance_loss
|
259 |
+
else:
|
260 |
+
loss_function = None
|
261 |
+
|
262 |
+
for i in range(num_styles):
|
263 |
+
generated_img = generate_images(prompt,style_num = i,random_seed = seed_values[i],custom_loss_fn = None)
|
264 |
+
images_without_loss.append(generated_img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
if loss_function:
|
266 |
+
generated_img = generate_images(prompt,style_num = i,random_seed = seed_values[i],custom_loss_fn = loss_function)
|
267 |
+
images_with_loss.append(generated_img)
|
268 |
+
|
269 |
+
generated_sd_images = []
|
270 |
+
titles = ["Arcane Style", "Birb Style", "Dr Strange Style", "Midjourney Style", "Oil Style"]
|
271 |
+
|
272 |
+
for i in range(len(titles)):
|
273 |
+
generated_sd_images.append((images_without_loss[i], titles[i]))
|
274 |
+
if images_with_loss != []:
|
275 |
+
generated_sd_images.append((images_with_loss[i], titles[i]))
|
276 |
+
|
|
|
277 |
|
278 |
+
return display_images_in_rows(generated_sd_images, titles)
|
279 |
|
280 |
# Create a wrapper function for show_misclassified_images()
|
281 |
def image_generator_wrapper(prompt = "dog", loss_function=None):
|
282 |
+
if loss_function == "Yes":
|
283 |
+
loss_function = vibrance_loss
|
284 |
+
else:
|
285 |
+
loss_function = None
|
286 |
|
287 |
+
return image_generator(prompt, loss_function)
|
288 |
|
289 |
+
description = "Generate an image with a prompt and apply vibrance loss if you wish to"
|
290 |
|
291 |
demo = gr.Interface(image_generator,
|
292 |
+
inputs=[gr.Textbox(label="Enter prompt for generation", type="text", value="dog sitting on a bench"),
|
293 |
gr.Radio(["Yes", "No"], value="No" , label="Apply vibrance loss")],
|
294 |
+
outputs=gr.Plot(label="Generated Images"), title = "Stable Diffusion", description=description)
|
295 |
+
demo.launch()
|