primerz commited on
Commit
2e66212
·
verified ·
1 Parent(s): 49f6b6d

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +39 -0
model.py CHANGED
@@ -118,6 +118,45 @@ class ModelHandler:
118
  print(f" [WARNING] Failed to enable xFormers: {e}")
119
  # --- END NEW ---
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  # 4. Set Scheduler
122
  # --- MODIFIED: Disable clipping to prevent NaN artifacts ---
123
  print("Configuring LCMScheduler...")
 
118
  print(f" [WARNING] Failed to enable xFormers: {e}")
119
  # --- END NEW ---
120
 
121
+ # ==============================================================================
122
+ # 3.5 LOAD PIVOTAL TUNING EMBEDDINGS (TEXTUAL INVERSION)
123
+ # ==============================================================================
124
+ print("Loading Textual Inversion Embeddings (Pivotal Tuning)...")
125
+
126
+ # Define the embedding name (assumed to be in the same repo as Config.REPO_ID)
127
+ embedding_filename = "retroart.safetensors"
128
+ embedding_path = os.path.join("./models", embedding_filename)
129
+
130
+ # 1. Download if missing
131
+ if not os.path.exists(embedding_path):
132
+ print(f"Downloading embedding '{embedding_filename}' to {embedding_path}...")
133
+ try:
134
+ hf_hub_download(
135
+ repo_id=Config.REPO_ID, # Or 'primerz/pixagram' if separate
136
+ filename=embedding_filename,
137
+ local_dir="./models",
138
+ local_dir_use_symlinks=False
139
+ )
140
+ except Exception as e:
141
+ print(f" [WARNING] Could not download embedding: {e}")
142
+
143
+ # 2. Load into the pipeline
144
+ # SDXL pipelines automatically handle loading into both tokenizers/text_encoders
145
+ if os.path.exists(embedding_path):
146
+ try:
147
+ self.pipeline.load_textual_inversion(
148
+ embedding_path,
149
+ token="retroart", # Trigger word: <retroart> or retroart
150
+ local_files_only=True
151
+ )
152
+ print(f" [OK] Loaded embedding '{embedding_filename}' associated with token 'retroart'.")
153
+ except Exception as e:
154
+ print(f" [ERROR] Failed to load textual inversion: {e}")
155
+ else:
156
+ print(f" [SKIP] Embedding file not found locally.")
157
+ # ==============================================================================
158
+
159
+
160
  # 4. Set Scheduler
161
  # --- MODIFIED: Disable clipping to prevent NaN artifacts ---
162
  print("Configuring LCMScheduler...")