annoyingpixel commited on
Commit
df05acf
·
verified ·
1 Parent(s): a4355c4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +60 -6
app.py CHANGED
@@ -62,6 +62,27 @@ class FluxSpaceApp:
62
  # LoRA Management
63
  gr.Markdown("### LoRA Management")
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  lora_upload = gr.File(
66
  label="Upload LoRA (.safetensors)",
67
  file_types=[".safetensors"],
@@ -78,12 +99,11 @@ class FluxSpaceApp:
78
  maximum=2.0,
79
  value=1.0,
80
  step=0.1,
81
- label="LoRA Strength",
82
- info="How strongly to apply the LoRA"
83
  )
84
 
85
  with gr.Row():
86
- load_lora_btn = gr.Button("Load LoRA", variant="secondary")
87
  unload_lora_btn = gr.Button("Unload LoRA", variant="stop")
88
 
89
  # LoRA Status
@@ -211,11 +231,39 @@ class FluxSpaceApp:
211
  except Exception as e:
212
  return f"Error: {str(e)}", "Error: Model loading failed"
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  def load_lora_handler(file, name, strength):
215
- """Handle LoRA loading"""
216
  try:
217
  if file is None:
218
- return "Error: No file uploaded", "LoRAs: None loaded"
219
 
220
  file_path = file.name
221
  lora_name = name if name else os.path.splitext(os.path.basename(file_path))[0]
@@ -235,7 +283,7 @@ class FluxSpaceApp:
235
  # Update LoRA list
236
  lora_list = list(self.lora_manager.loaded_loras.keys())
237
 
238
- status_text = f"LoRA Loaded: {lora_name}"
239
  lora_status_text = f"LoRAs: {', '.join(lora_list)}"
240
 
241
  return status_text, lora_status_text, lora_list
@@ -298,6 +346,12 @@ LoRAs: {', '.join(gen_info['loras']) if gen_info['loras'] else 'None'}
298
  outputs=[model_status, model_info]
299
  )
300
 
 
 
 
 
 
 
301
  load_lora_btn.click(
302
  fn=load_lora_handler,
303
  inputs=[lora_upload, lora_name, lora_strength],
 
62
  # LoRA Management
63
  gr.Markdown("### LoRA Management")
64
 
65
+ # Pre-loaded LoRAs
66
+ gr.Markdown("#### Pre-loaded LoRAs")
67
+ preloaded_lora_selector = gr.Dropdown(
68
+ choices=["T11-Ultra-Portrait-E04"],
69
+ value=None,
70
+ label="Select Pre-loaded LoRA",
71
+ info="Load LoRAs directly from Hugging Face"
72
+ )
73
+
74
+ preloaded_lora_strength = gr.Slider(
75
+ minimum=0.0,
76
+ maximum=2.0,
77
+ value=1.0,
78
+ step=0.1,
79
+ label="Pre-loaded LoRA Strength"
80
+ )
81
+
82
+ load_preloaded_lora_btn = gr.Button("Load Pre-loaded LoRA", variant="secondary")
83
+
84
+ # Custom LoRA Upload
85
+ gr.Markdown("#### Custom LoRA Upload")
86
  lora_upload = gr.File(
87
  label="Upload LoRA (.safetensors)",
88
  file_types=[".safetensors"],
 
99
  maximum=2.0,
100
  value=1.0,
101
  step=0.1,
102
+ label="Custom LoRA Strength"
 
103
  )
104
 
105
  with gr.Row():
106
+ load_lora_btn = gr.Button("Load Custom LoRA", variant="secondary")
107
  unload_lora_btn = gr.Button("Unload LoRA", variant="stop")
108
 
109
  # LoRA Status
 
231
  except Exception as e:
232
  return f"Error: {str(e)}", "Error: Model loading failed"
233
 
234
+ def load_preloaded_lora_handler(lora_name, strength):
235
+ """Handle pre-loaded LoRA loading"""
236
+ try:
237
+ if not lora_name:
238
+ return "Error: No LoRA selected", "LoRAs: None loaded", []
239
+
240
+ # Load pre-loaded LoRA
241
+ success = self.model_manager.load_preloaded_lora(lora_name, strength)
242
+
243
+ if success:
244
+ # Get trigger words
245
+ lora_info = self.model_manager.get_preloaded_loras().get(lora_name, {})
246
+ trigger_words = lora_info.get('trigger_words', '')
247
+
248
+ status_text = f"Pre-loaded LoRA Loaded: {lora_name}"
249
+ if trigger_words:
250
+ status_text += f" (Trigger: {trigger_words})"
251
+
252
+ lora_status_text = f"LoRAs: {lora_name}"
253
+ lora_list = [lora_name]
254
+
255
+ return status_text, lora_status_text, lora_list
256
+ else:
257
+ return f"Error: Failed to load pre-loaded LoRA", "LoRAs: None loaded", []
258
+
259
+ except Exception as e:
260
+ return f"Error: {str(e)}", "LoRAs: None loaded", []
261
+
262
  def load_lora_handler(file, name, strength):
263
+ """Handle custom LoRA loading"""
264
  try:
265
  if file is None:
266
+ return "Error: No file uploaded", "LoRAs: None loaded", []
267
 
268
  file_path = file.name
269
  lora_name = name if name else os.path.splitext(os.path.basename(file_path))[0]
 
283
  # Update LoRA list
284
  lora_list = list(self.lora_manager.loaded_loras.keys())
285
 
286
+ status_text = f"Custom LoRA Loaded: {lora_name}"
287
  lora_status_text = f"LoRAs: {', '.join(lora_list)}"
288
 
289
  return status_text, lora_status_text, lora_list
 
346
  outputs=[model_status, model_info]
347
  )
348
 
349
+ load_preloaded_lora_btn.click(
350
+ fn=load_preloaded_lora_handler,
351
+ inputs=[preloaded_lora_selector, preloaded_lora_strength],
352
+ outputs=[lora_status, lora_status, lora_list]
353
+ )
354
+
355
  load_lora_btn.click(
356
  fn=load_lora_handler,
357
  inputs=[lora_upload, lora_name, lora_strength],