Spaces:
Build error
Build error
Update generate.py
Browse files- generate.py +13 -9
generate.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# generate.py
|
| 2 |
-
# --- VERSION
|
| 3 |
|
| 4 |
-
print("--- RUNNING GENERATE.PY VERSION
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import cv2
|
|
@@ -9,6 +9,7 @@ import os
|
|
| 9 |
import logging
|
| 10 |
import uuid
|
| 11 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
|
|
|
|
| 12 |
from transformers import CLIPVisionModelWithProjection
|
| 13 |
from insightface.app import FaceAnalysis
|
| 14 |
from insightface.utils import face_align
|
|
@@ -22,10 +23,6 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(level
|
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
| 24 |
|
| 25 |
-
# --- IP-Adapter FaceID Model (Placeholder) ---
|
| 26 |
-
# The complex IP-Adapter logic is assumed to be part of the diffusers pipeline for this implementation.
|
| 27 |
-
|
| 28 |
-
|
| 29 |
# --- Main Generation Service ---
|
| 30 |
class GenerationService:
|
| 31 |
def __init__(self):
|
|
@@ -95,8 +92,9 @@ class GenerationService:
|
|
| 95 |
try:
|
| 96 |
final_embedding = average_embedding.unsqueeze(0)
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
|
|
|
| 100 |
prompt=full_prompt,
|
| 101 |
negative_prompt=negative_prompt,
|
| 102 |
ip_adapter_image_embeds=[final_embedding],
|
|
@@ -105,7 +103,13 @@ class GenerationService:
|
|
| 105 |
width=512,
|
| 106 |
height=768,
|
| 107 |
)
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
# --- Save image locally first ---
|
| 111 |
temp_dir = "temp_images"
|
|
|
|
| 1 |
# generate.py
|
| 2 |
+
# --- VERSION 6 ---
|
| 3 |
|
| 4 |
+
print("--- RUNNING GENERATE.PY VERSION 6 ---")
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import cv2
|
|
|
|
| 9 |
import logging
|
| 10 |
import uuid
|
| 11 |
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
|
| 12 |
+
from diffusers.pipelines.stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
|
| 13 |
from transformers import CLIPVisionModelWithProjection
|
| 14 |
from insightface.app import FaceAnalysis
|
| 15 |
from insightface.utils import face_align
|
|
|
|
| 23 |
logger = logging.getLogger(__name__)
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# --- Main Generation Service ---
|
| 27 |
class GenerationService:
|
| 28 |
def __init__(self):
|
|
|
|
| 92 |
try:
|
| 93 |
final_embedding = average_embedding.unsqueeze(0)
|
| 94 |
|
| 95 |
+
# --- ROBUST FIX for diffusers version mismatch ---
|
| 96 |
+
# This handles both old and new output formats from the pipeline.
|
| 97 |
+
output = self.pipe(
|
| 98 |
prompt=full_prompt,
|
| 99 |
negative_prompt=negative_prompt,
|
| 100 |
ip_adapter_image_embeds=[final_embedding],
|
|
|
|
| 103 |
width=512,
|
| 104 |
height=768,
|
| 105 |
)
|
| 106 |
+
|
| 107 |
+
# Check if the output is the modern object or an old tuple
|
| 108 |
+
if isinstance(output, StableDiffusionPipelineOutput):
|
| 109 |
+
image = output.images[0]
|
| 110 |
+
else:
|
| 111 |
+
# Handle older tuple-based output
|
| 112 |
+
image = output[0][0]
|
| 113 |
|
| 114 |
# --- Save image locally first ---
|
| 115 |
temp_dir = "temp_images"
|