AkashKumarave commited on
Commit
c701a24
·
verified ·
1 Parent(s): a1bd508

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -7,6 +7,7 @@ from insightface.app import FaceAnalysis
7
  from huggingface_hub import hf_hub_download
8
  import os
9
  import logging
 
10
 
11
  # Set up detailed logging
12
  logging.basicConfig(level=logging.INFO)
@@ -74,7 +75,7 @@ ip_adapter_weights = download_file(
74
  ip_adapter_path
75
  )
76
 
77
- # Load the pipeline with verbose logging
78
  logger.info("Loading Stable Diffusion XL base model...")
79
  try:
80
  pipe = StableDiffusionXLPipeline.from_pretrained(
@@ -83,18 +84,18 @@ try:
83
  safety_checker=None,
84
  local_files_only=False,
85
  cache_dir=cache_dir,
86
- variant="fp16", # Use FP16 weights to reduce memory usage
87
- use_safetensors=True # Prefer safetensors format if available
88
  )
89
  logger.info("SDXL base model loaded successfully.")
90
  except Exception as e:
91
  logger.error(f"Failed to load SDXL base model: {e}")
92
  raise
93
 
94
- # Load Kolors unet weights
95
  logger.info(f"Loading Kolors unet weights from {kolors_weights}...")
96
  try:
97
- state_dict = torch.load(kolors_weights, map_location=device, weights_only=False)
98
  pipe.unet.load_state_dict(state_dict)
99
  logger.info("Kolors unet weights loaded successfully.")
100
  except Exception as e:
@@ -131,9 +132,9 @@ def generate_image(uploaded_image, prompt):
131
  image = pipe(
132
  prompt=prompt,
133
  image_embeds=face_emb,
134
- num_inference_steps=10, # Reduced steps for faster execution
135
  guidance_scale=7.5,
136
- height=256, # Smaller resolution to fit memory
137
  width=256
138
  ).images[0]
139
  logger.info("Image generated successfully.")
 
7
  from huggingface_hub import hf_hub_download
8
  import os
9
  import logging
10
+ from safetensors.torch import load_file # Import safetensors loader
11
 
12
  # Set up detailed logging
13
  logging.basicConfig(level=logging.INFO)
 
75
  ip_adapter_path
76
  )
77
 
78
+ # Load the pipeline
79
  logger.info("Loading Stable Diffusion XL base model...")
80
  try:
81
  pipe = StableDiffusionXLPipeline.from_pretrained(
 
84
  safety_checker=None,
85
  local_files_only=False,
86
  cache_dir=cache_dir,
87
+ variant="fp16",
88
+ use_safetensors=True
89
  )
90
  logger.info("SDXL base model loaded successfully.")
91
  except Exception as e:
92
  logger.error(f"Failed to load SDXL base model: {e}")
93
  raise
94
 
95
+ # Load Kolors unet weights using safetensors
96
  logger.info(f"Loading Kolors unet weights from {kolors_weights}...")
97
  try:
98
+ state_dict = load_file(kolors_weights, device=device) # Use safetensors loader
99
  pipe.unet.load_state_dict(state_dict)
100
  logger.info("Kolors unet weights loaded successfully.")
101
  except Exception as e:
 
132
  image = pipe(
133
  prompt=prompt,
134
  image_embeds=face_emb,
135
+ num_inference_steps=10,
136
  guidance_scale=7.5,
137
+ height=256,
138
  width=256
139
  ).images[0]
140
  logger.info("Image generated successfully.")