aanchal77 commited on
Commit
61ee5f7
·
verified ·
1 Parent(s): 30b8639

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -6
app.py CHANGED
@@ -41,11 +41,35 @@ if device == "cpu":
41
  pipe.enable_attention_slicing()
42
 
43
  # --- The Core Generation Function ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  def generate(prompt, quality, lora_choice):
45
- """
46
- Generates an image, dynamically loading the selected LoRA from the Hub.
47
- """
48
- # Unload any existing LoRA to reset to the base model
49
  pipe.unload_lora_weights()
50
 
51
  lora_subfolder = AVAILABLE_LORAS.get(lora_choice)
@@ -53,8 +77,11 @@ def generate(prompt, quality, lora_choice):
53
  if lora_subfolder:
54
  print(f"✨ Downloading and applying LoRA: {lora_choice}")
55
  try:
56
- # Load LoRA directly from the Hugging Face Hub
57
- pipe.load_lora_weights(HF_REPO_ID, subfolder=lora_subfolder)
 
 
 
58
  except Exception as e:
59
  print(f"❌ Failed to load LoRA from Hub '{HF_REPO_ID}/{lora_subfolder}': {e}")
60
  else:
@@ -69,6 +96,7 @@ def generate(prompt, quality, lora_choice):
69
 
70
  return image
71
 
 
72
  # --- Build the Gradio UI ---
73
  title = f"🎨 Stable Diffusion Gallery from {HF_REPO_ID}"
74
  description = "Select a trained LoRA model from your Hugging Face repository to apply its style. The first time you select a LoRA, it may take a moment to download."
 
41
  pipe.enable_attention_slicing()
42
 
43
  # --- The Core Generation Function ---
44
+ # def generate(prompt, quality, lora_choice):
45
+ # """
46
+ # Generates an image, dynamically loading the selected LoRA from the Hub.
47
+ # """
48
+ # # Unload any existing LoRA to reset to the base model
49
+ # pipe.unload_lora_weights()
50
+
51
+ # lora_subfolder = AVAILABLE_LORAS.get(lora_choice)
52
+
53
+ # if lora_subfolder:
54
+ # print(f"✨ Downloading and applying LoRA: {lora_choice}")
55
+ # try:
56
+ # # Load LoRA directly from the Hugging Face Hub
57
+ # pipe.load_lora_weights(HF_REPO_ID, subfolder=lora_subfolder)
58
+ # except Exception as e:
59
+ # print(f"❌ Failed to load LoRA from Hub '{HF_REPO_ID}/{lora_subfolder}': {e}")
60
+ # else:
61
+ # print("🎨 Using base model (no LoRA selected)")
62
+
63
+ # steps = 25 if quality == "Fast" else 40
64
+ # guidance_scale = 7.5
65
+
66
+ # print(f"🚀 Generating with prompt: '{prompt}'")
67
+ # with torch.no_grad():
68
+ # image = pipe(prompt, num_inference_steps=steps, guidance_scale=guidance_scale).images[0]
69
+
70
+ # return image
71
  def generate(prompt, quality, lora_choice):
72
+ # Reset to base model
 
 
 
73
  pipe.unload_lora_weights()
74
 
75
  lora_subfolder = AVAILABLE_LORAS.get(lora_choice)
 
77
  if lora_subfolder:
78
  print(f"✨ Downloading and applying LoRA: {lora_choice}")
79
  try:
80
+ pipe.load_lora_weights(
81
+ HF_REPO_ID,
82
+ subfolder=lora_subfolder,
83
+ weight_name="adapter_model.safetensors" # 👈 specify the file
84
+ )
85
  except Exception as e:
86
  print(f"❌ Failed to load LoRA from Hub '{HF_REPO_ID}/{lora_subfolder}': {e}")
87
  else:
 
96
 
97
  return image
98
 
99
+
100
  # --- Build the Gradio UI ---
101
  title = f"🎨 Stable Diffusion Gallery from {HF_REPO_ID}"
102
  description = "Select a trained LoRA model from your Hugging Face repository to apply its style. The first time you select a LoRA, it may take a moment to download."