kayte0342 commited on
Commit
8f7f8fc
·
verified ·
1 Parent(s): 3b79313

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -39,6 +39,14 @@ else:
39
  with open('loras.json', 'r') as f:
40
  loras = json.load(f)
41
 
 
 
 
 
 
 
 
 
42
  # Initialize the base model
43
  dtype = torch.bfloat16
44
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -81,6 +89,16 @@ class calculateDuration:
81
  else:
82
  print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
83
 
 
 
 
 
 
 
 
 
 
 
84
  def update_selection(evt: gr.SelectData, width, height):
85
  selected_lora = loras[evt.index]
86
  new_placeholder = f"Type a prompt for {selected_lora['title']}"
@@ -143,6 +161,10 @@ def generate_image_to_image(prompt_mash, image_input_path, image_strength, steps
143
 
144
  @spaces.GPU(duration=70)
145
  def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_indices, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
146
  # Ensure at least one LoRA is selected
147
  if not selected_indices or len(selected_indices) == 0:
148
  raise gr.Error("You must select at least one LoRA before proceeding.")
 
39
  with open('loras.json', 'r') as f:
40
  loras = json.load(f)
41
 
42
+ # Create a list of options for the LoRAs.
43
+ # You could use the index or a descriptive label.
44
+ lora_options = [f"{idx}: {lora['title']}" for idx, lora in enumerate(loras)]
45
+
46
+ # Create a CheckboxGroup that returns a list of selected options (as strings)
47
+ selected_lora_indices = gr.CheckboxGroup(choices=lora_options, label="Select LoRAs to load", value=[])
48
+
49
+
50
  # Initialize the base model
51
  dtype = torch.bfloat16
52
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
89
  else:
90
  print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
91
 
92
+ def parse_selected_indices(selected_options):
93
+ indices = []
94
+ for option in selected_options:
95
+ try:
96
+ index = int(option.split(":")[0])
97
+ indices.append(index)
98
+ except Exception:
99
+ continue
100
+ return indices
101
+
102
  def update_selection(evt: gr.SelectData, width, height):
103
  selected_lora = loras[evt.index]
104
  new_placeholder = f"Type a prompt for {selected_lora['title']}"
 
161
 
162
  @spaces.GPU(duration=70)
163
  def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_indices, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
164
+ print("Selected indices (raw):", selected_indices)
165
+ # Then parse them if needed
166
+ parsed_indices = parse_selected_indices(selected_indices)
167
+ print("Parsed indices:", parsed_indices)
168
  # Ensure at least one LoRA is selected
169
  if not selected_indices or len(selected_indices) == 0:
170
  raise gr.Error("You must select at least one LoRA before proceeding.")