rastof9 commited on
Commit
25372f4
·
verified ·
1 Parent(s): 6cd47db

Update generate.py

Browse files
Files changed (1) hide show
  1. generate.py +11 -11
generate.py CHANGED
@@ -1,14 +1,14 @@
1
  # generate.py
2
- # --- VERSION 7 ---
3
 
4
- print("--- RUNNING GENERATE.PY VERSION 7 (WITH TRACEBACK) ---")
5
 
6
  import torch
7
  import cv2
8
  import os
9
  import logging
10
  import uuid
11
- import traceback # <-- ADDED FOR DETAILED ERROR LOGGING
12
  from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
13
  from diffusers.pipelines.stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
14
  from transformers import CLIPVisionModelWithProjection
@@ -88,7 +88,14 @@ class GenerationService:
88
 
89
  logger.info("Calling the generation pipeline...")
90
  try:
91
- final_embedding = average_embedding.unsqueeze(0)
 
 
 
 
 
 
 
92
 
93
  output = self.pipe(
94
  prompt=full_prompt,
@@ -127,16 +134,9 @@ class GenerationService:
127
 
128
  return public_url
129
 
130
- except StorageException as e:
131
- logger.error(f"Supabase Storage Error: {e}")
132
- return None
133
  except Exception as e:
134
- # --- THIS IS THE IMPORTANT PART ---
135
- # It will print the full error details to the log.
136
  logger.error("An unexpected error occurred. Full traceback below:")
137
  traceback.print_exc()
138
- # ---
139
-
140
  logger.error(f"Error summary: {e}")
141
  if 'local_path' in locals() and os.path.exists(local_path):
142
  os.remove(local_path)
 
1
  # generate.py
2
+ # --- VERSION 8 (FINAL) ---
3
 
4
+ print("--- RUNNING GENERATE.PY VERSION 8 (FINAL) ---")
5
 
6
  import torch
7
  import cv2
8
  import os
9
  import logging
10
  import uuid
11
+ import traceback
12
  from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
13
  from diffusers.pipelines.stable_diffusion.pipeline_output import StableDiffusionPipelineOutput
14
  from transformers import CLIPVisionModelWithProjection
 
88
 
89
  logger.info("Calling the generation pipeline...")
90
  try:
91
+ # --- FINAL FIX: Create negative embeddings ---
92
+ # The IP-Adapter expects both positive and negative image embeddings.
93
+ # We create a zeroed-out tensor for the negative part.
94
+ positive_embedding = average_embedding.unsqueeze(0)
95
+ negative_embedding = torch.zeros_like(positive_embedding)
96
+
97
+ # Combine them for the pipeline
98
+ final_embedding = torch.cat([negative_embedding, positive_embedding], dim=0)
99
 
100
  output = self.pipe(
101
  prompt=full_prompt,
 
134
 
135
  return public_url
136
 
 
 
 
137
  except Exception as e:
 
 
138
  logger.error("An unexpected error occurred. Full traceback below:")
139
  traceback.print_exc()
 
 
140
  logger.error(f"Error summary: {e}")
141
  if 'local_path' in locals() and os.path.exists(local_path):
142
  os.remove(local_path)