minakshi.mathpal commited on
Commit ·
9024e9d
1
Parent(s): 5ac005e
changes made to all the files
Browse files- custom_stable_diffusion.py +48 -23
custom_stable_diffusion.py
CHANGED
|
@@ -340,18 +340,35 @@ def generate_with_multiple_concepts(models, config, image_processor, prompt, con
|
|
| 340 |
"""
|
| 341 |
os.makedirs(output_dir, exist_ok=True)
|
| 342 |
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
#
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
| 349 |
for concept in concepts:
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
return pil_image
|
| 353 |
|
| 354 |
-
# If we get here, return None
|
| 355 |
return None
|
| 356 |
|
| 357 |
def channel_loss(images, channel_idx=2, target_value=0.9):
|
|
@@ -585,25 +602,28 @@ def generate_with_concept_and_color(
|
|
| 585 |
|
| 586 |
return pil_image
|
| 587 |
|
| 588 |
-
|
| 589 |
-
def generate_with_multiple_concepts_and_color(
|
| 590 |
-
models,
|
| 591 |
-
config,
|
| 592 |
-
image_processor,
|
| 593 |
-
prompt,
|
| 594 |
-
concepts,
|
| 595 |
-
output_dir="concept_images",
|
| 596 |
-
blue_loss_scale=0,
|
| 597 |
-
yellow_loss_scale=0
|
| 598 |
-
):
|
| 599 |
"""
|
| 600 |
Generate images using multiple concepts and color guidance
|
| 601 |
"""
|
| 602 |
os.makedirs(output_dir, exist_ok=True)
|
| 603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
for concept in concepts:
|
| 605 |
-
|
| 606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
models=models,
|
| 608 |
config=config,
|
| 609 |
image_processor=image_processor,
|
|
@@ -613,7 +633,12 @@ def generate_with_multiple_concepts_and_color(
|
|
| 613 |
blue_loss_scale=blue_loss_scale,
|
| 614 |
yellow_loss_scale=yellow_loss_scale
|
| 615 |
)
|
| 616 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
|
| 618 |
# Example usage
|
| 619 |
if __name__ == "__main__":
|
|
|
|
| 340 |
"""
|
| 341 |
os.makedirs(output_dir, exist_ok=True)
|
| 342 |
|
| 343 |
+
# If no concepts provided, generate a standard image
|
| 344 |
+
if not concepts or len(concepts) == 0:
|
| 345 |
+
print("No concepts provided, generating standard image")
|
| 346 |
+
# Create a standard image without concepts
|
| 347 |
+
# You'll need to implement this part based on your existing code
|
| 348 |
+
# For now, return None
|
| 349 |
+
return None
|
| 350 |
+
|
| 351 |
+
# Process each concept
|
| 352 |
for concept in concepts:
|
| 353 |
+
if concept is None:
|
| 354 |
+
continue
|
| 355 |
+
|
| 356 |
+
print(f"Generating image for concept: {concept}")
|
| 357 |
+
concepts_dir = os.path.join(output_dir, concept)
|
| 358 |
+
os.makedirs(concepts_dir, exist_ok=True)
|
| 359 |
+
|
| 360 |
+
output_path = os.path.join(concepts_dir, f"{concept}.png")
|
| 361 |
+
|
| 362 |
+
text_processor = TextEmbeddingProcessor(models, config, image_processor, prompt)
|
| 363 |
+
|
| 364 |
+
# Generate the image with the concept
|
| 365 |
+
pil_image = text_processor.prepare_embeddings_with_concepts(prompt, concept_name=concept, output_path=output_path)
|
| 366 |
+
print(f"Saved image to {output_path}")
|
| 367 |
+
|
| 368 |
+
# Return the generated image
|
| 369 |
return pil_image
|
| 370 |
|
| 371 |
+
# If we get here (no valid concepts processed), return None
|
| 372 |
return None
|
| 373 |
|
| 374 |
def channel_loss(images, channel_idx=2, target_value=0.9):
|
|
|
|
| 602 |
|
| 603 |
return pil_image
|
| 604 |
|
| 605 |
+
def generate_with_multiple_concepts_and_color(models, config, image_processor, prompt, concepts, output_dir="concept_images", blue_loss_scale=0, yellow_loss_scale=0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 606 |
"""
|
| 607 |
Generate images using multiple concepts and color guidance
|
| 608 |
"""
|
| 609 |
os.makedirs(output_dir, exist_ok=True)
|
| 610 |
|
| 611 |
+
# If no concepts provided, generate a standard image with color guidance
|
| 612 |
+
if not concepts or len(concepts) == 0:
|
| 613 |
+
print("No concepts provided, generating standard image with color guidance")
|
| 614 |
+
# Create a standard image with color guidance but without concepts
|
| 615 |
+
# You'll need to implement this part based on your existing code
|
| 616 |
+
# For now, return None
|
| 617 |
+
return None
|
| 618 |
+
|
| 619 |
+
# Process each concept
|
| 620 |
for concept in concepts:
|
| 621 |
+
if concept is None:
|
| 622 |
+
continue
|
| 623 |
+
|
| 624 |
+
print(f"Generating image for concept: {concept} with color guidance")
|
| 625 |
+
# Generate the image with the concept and color guidance
|
| 626 |
+
pil_image = generate_with_concept_and_color(
|
| 627 |
models=models,
|
| 628 |
config=config,
|
| 629 |
image_processor=image_processor,
|
|
|
|
| 633 |
blue_loss_scale=blue_loss_scale,
|
| 634 |
yellow_loss_scale=yellow_loss_scale
|
| 635 |
)
|
| 636 |
+
|
| 637 |
+
# Return the generated image
|
| 638 |
+
return pil_image
|
| 639 |
+
|
| 640 |
+
# If we get here (no valid concepts processed), return None
|
| 641 |
+
return None
|
| 642 |
|
| 643 |
# Example usage
|
| 644 |
if __name__ == "__main__":
|