Spaces:
Build error
Build error
Update generate.py
Browse files76 unmodified lines777879808182833 unmodified lines8788899091929394959697989910010110210310410510610710810911011111211376 unmodified linesfaces = self.face_app.get(face)if faces:# Shape of normed_embedding is (512,). .unsqueeze(0) makes it (1, 512)faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)faceid_all_embeds.append(faceid_embed)except Exception as e:3 unmodified lineslogger.error("No faces were detected in any of the provided images.")return None# Stack embeds into a single tensor and calculate the average# Shape of stacked tensor: (num_images, 1, 512)# Shape of average_embedding: (1, 512)average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)logger.info("Calling the generation pipeline...")try:# FIX: The pipeline expects a 3D or 4D tensor.# We add a "sequence length" dimension of 1.# Shape becomes: (1, 1, 512)final_embedding = average_embedding.unsqueeze(0)image = self.pipe(prompt=full_prompt,negative_prompt=negative_prompt,ip_adapter_image_embeds=[final_embedding], # Pass the correctly shaped tensornum_inference_steps=40,guidance_scale=7.5,width=512,height=768,).images[0]# --- Save image locally first ---temp_dir = "temp_images"76 unmodified lines7778798081823 unmodified lines868788899091929394959697989910010110210310410510610710876 unmodified linesfaces = self.face_app.get(face)if faces:faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)faceid_all_embeds.append(faceid_embed)except Exception as e:3 unmodified lineslogger.error("No faces were detected in any of the provided images.")return Noneaverage_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)logger.info("Calling the generation pipeline...")try:final_embedding = average_embedding.unsqueeze(0)# FIX: The pipeline returns an object, not a tuple. Access the .images attribute.pipeline_output = self.pipe(prompt=full_prompt,negative_prompt=negative_prompt,ip_adapter_image_embeds=[final_embedding],num_inference_steps=40,guidance_scale=7.5,width=512,height=768,)image = pipeline_output.images[0]# --- Save image locally first ---temp_dir = "temp_images"
generate.py+5-10