multimodalart HF staff commited on
Commit
5ecece8
1 Parent(s): 03a5380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -36,15 +36,24 @@ class calculateDuration:
36
  print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
37
 
38
 
39
- def update_selection(evt: gr.SelectData):
40
  selected_lora = loras[evt.index]
41
  new_placeholder = f"Type a prompt for {selected_lora['title']}"
42
  lora_repo = selected_lora["repo"]
43
  updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo}) ✨"
 
 
 
 
 
 
 
44
  return (
45
  gr.update(placeholder=new_placeholder),
46
  updated_text,
47
- evt.index
 
 
48
  )
49
 
50
  @spaces.GPU(duration=70)
@@ -138,7 +147,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
138
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
139
  lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=0.95)
140
 
141
- gallery.select(update_selection, outputs=[prompt, selected_info, selected_index])
 
 
 
 
142
 
143
  gr.on(
144
  triggers=[generate_button.click, prompt.submit],
 
36
  print(f"Elapsed time: {self.elapsed_time:.6f} seconds")
37
 
38
 
39
+ def update_selection(evt: gr.SelectData, width, height):
40
  selected_lora = loras[evt.index]
41
  new_placeholder = f"Type a prompt for {selected_lora['title']}"
42
  lora_repo = selected_lora["repo"]
43
  updated_text = f"### Selected: [{lora_repo}](https://huggingface.co/{lora_repo}) ✨"
44
+ if "aspect" in selected_lora:
45
+ if selected_lora["aspect"] == "portrait":
46
+ width = 768
47
+ height = 1024
48
+ elif selected_lora["aspect"] == "landscape":
49
+ width = 1024
50
+ height = 768
51
  return (
52
  gr.update(placeholder=new_placeholder),
53
  updated_text,
54
+ evt.index,
55
+ width,
56
+ height,
57
  )
58
 
59
  @spaces.GPU(duration=70)
 
147
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
148
  lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=0.95)
149
 
150
+ gallery.select(
151
+ update_selection,
152
+ inputs=[width, height]
153
+ outputs=[prompt, selected_info, selected_index, width, height]
154
+ )
155
 
156
  gr.on(
157
  triggers=[generate_button.click, prompt.submit],