Vector857 commited on
Commit
faa6afa
·
verified ·
1 Parent(s): 74d5b79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -270,17 +270,18 @@ def format_history_html(history: list) -> str:
270
 
271
  @spaces.GPU(duration=100)
272
  def generate(
273
- prompt, neg_prompt, cfg_sale, steps, selected_index,
274
  randomize_seed, seed, aspect_ratio, lora_scale, speed_mode,
275
  history_state,
276
  oauth_token: gr.OAuthToken | None = None,
277
  progress=gr.Progress(track_tqdm=True),
278
  ):
279
  try:
 
280
  pipe.unload_lora_weights()
281
  torch.cuda.empty_cache()
282
  except Exception as e:
283
- print(f"Unload error (ithu paravaillai): {e}")
284
 
285
  if oauth_token is None:
286
  raise gr.Error("Please sign in with your HuggingFace account to generate images.")
@@ -291,8 +292,7 @@ def generate(
291
  trigger = lora["trigger_word"]
292
  prompt_in = f"{trigger} {prompt}" if trigger else prompt
293
 
294
- pipe.to("cuda")
295
-
296
  if speed_mode == "Fast · 8 steps":
297
  pipe.load_lora_weights(LIGHTNING_REPO, weight_name=LIGHTNING_WEIGHT, adapter_name="lightning")
298
  pipe.load_lora_weights(lora["repo"], weight_name=lora.get("weights"), low_cpu_mem_usage=True, adapter_name="style")
@@ -306,20 +306,23 @@ def generate(
306
 
307
  w, h = aspect_to_wh(aspect_ratio)
308
  generator = torch.Generator(device="cuda").manual_seed(seed)
309
-
 
310
  image = pipe(
311
  prompt=prompt_in,
312
  negative_prompt=neg_prompt,
313
  num_inference_steps=steps,
314
  guidance_scale=cfg_scale,
315
  height=h,
 
316
  generator=generator,
317
  ).images[0]
318
-
 
319
  pipe.to("cpu")
320
  torch.cuda.empty_cache()
321
 
322
- new_meta = build_metadata_html(lora["title"], seed, steps, cfg_scale, aspect_ratio)
323
 
324
  import datetime
325
  history_entry = {
 
270
 
271
  @spaces.GPU(duration=100)
272
  def generate(
273
+ prompt, neg_prompt, cfg_scale, steps, selected_index,
274
  randomize_seed, seed, aspect_ratio, lora_scale, speed_mode,
275
  history_state,
276
  oauth_token: gr.OAuthToken | None = None,
277
  progress=gr.Progress(track_tqdm=True),
278
  ):
279
  try:
280
+ pipe.to("cuda")
281
  pipe.unload_lora_weights()
282
  torch.cuda.empty_cache()
283
  except Exception as e:
284
+ print(f"Unload error {e}")
285
 
286
  if oauth_token is None:
287
  raise gr.Error("Please sign in with your HuggingFace account to generate images.")
 
292
  trigger = lora["trigger_word"]
293
  prompt_in = f"{trigger} {prompt}" if trigger else prompt
294
 
295
+ # LoRA Loading Logic
 
296
  if speed_mode == "Fast · 8 steps":
297
  pipe.load_lora_weights(LIGHTNING_REPO, weight_name=LIGHTNING_WEIGHT, adapter_name="lightning")
298
  pipe.load_lora_weights(lora["repo"], weight_name=lora.get("weights"), low_cpu_mem_usage=True, adapter_name="style")
 
306
 
307
  w, h = aspect_to_wh(aspect_ratio)
308
  generator = torch.Generator(device="cuda").manual_seed(seed)
309
+
310
+ # Image Generation
311
  image = pipe(
312
  prompt=prompt_in,
313
  negative_prompt=neg_prompt,
314
  num_inference_steps=steps,
315
  guidance_scale=cfg_scale,
316
  height=h,
317
+ width=w,
318
  generator=generator,
319
  ).images[0]
320
+
321
+ # மெமரியை ரிலீஸ் செய்ய மீண்டும் CPU-வுக்கு மாற்றவும்
322
  pipe.to("cpu")
323
  torch.cuda.empty_cache()
324
 
325
+ metadata_html = build_metadata_html(lora["title"], seed, steps, cfg_scale, aspect_ratio)
326
 
327
  import datetime
328
  history_entry = {