multimodalart HF staff commited on
Commit
786f873
1 Parent(s): c7fa047

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -83,12 +83,14 @@ div#share-btn-container > div {flex-direction: row;background: black;align-items
83
  #post_gen_info{margin-top: .5em}
84
  #thumbs_up_clicked{background:green}
85
  #thumbs_down_clicked{background:red}
 
86
  '''
87
 
88
  original_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
89
 
90
  @spaces.GPU
91
  def merge_and_run(prompt, negative_prompt, shuffled_items, lora_1_scale=0.5, lora_2_scale=0.5, seed=-1, progress=gr.Progress(track_tqdm=True)):
 
92
  repo_id_1 = shuffled_items[0]['repo']
93
  repo_id_2 = shuffled_items[1]['repo']
94
  print("Loading state dicts...")
@@ -117,7 +119,11 @@ def merge_and_run(prompt, negative_prompt, shuffled_items, lora_1_scale=0.5, lor
117
  def get_description(item):
118
  trigger_word = item["trigger_word"]
119
  return f"Trigger: `{trigger_word}`" if trigger_word else "No trigger, applied automatically", trigger_word
120
-
 
 
 
 
121
  def shuffle_images():
122
  compatible_items = [item for item in sdxl_loras if item['is_compatible']]
123
  random.shuffle(compatible_items)
@@ -129,8 +135,8 @@ def shuffle_images():
129
  description_1, trigger_word_1 = get_description(two_shuffled_items[0])
130
  description_2, trigger_word_2 = get_description(two_shuffled_items[1])
131
 
132
- lora_1_link = f"[{two_shuffled_items[0]['repo']}](https://huggingface.co/{two_shuffled_items[0]['repo']}) ✨"
133
- lora_2_link = f"[{two_shuffled_items[1]['repo']}](https://huggingface.co/{two_shuffled_items[1]['repo']}) ✨"
134
  prompt_description_1 = gr.update(value=description_1, visible=True)
135
  prompt_description_2 = gr.update(value=description_2, visible=True)
136
  prompt = gr.update(value=f"{trigger_word_1} {trigger_word_2}")
@@ -160,14 +166,14 @@ with gr.Blocks(css=css) as demo:
160
  with gr.Column(min_width=10, scale=16, elem_classes="plus_column"):
161
  with gr.Row():
162
  with gr.Column(min_width=10, scale=4, elem_classes="random_column"):
163
- lora_1_link = gr.Markdown()
164
  lora_1 = gr.Image(interactive=False, show_label=False, height=150, elem_classes="selected_random", elem_id="randomLoRA_1", show_share_button=False, show_download_button=False)
165
  lora_1_id = gr.Textbox(visible=False, elem_id="random_lora_1_id")
166
  lora_1_prompt = gr.Markdown(visible=False)
167
  with gr.Column(min_width=10, scale=1, elem_classes="plus_column"):
168
  plus = gr.HTML("+", elem_classes="plus_button")
169
  with gr.Column(min_width=10, scale=4, elem_classes="random_column"):
170
- lora_2_link = gr.Markdown()
171
  lora_2 = gr.Image(interactive=False, show_label=False, height=150, elem_classes="selected_random", elem_id="randomLoRA_2", show_share_button=False, show_download_button=False)
172
  lora_2_id = gr.Textbox(visible=False, elem_id="random_lora_2_id")
173
  lora_2_prompt = gr.Markdown(visible=False)
 
83
  #post_gen_info{margin-top: .5em}
84
  #thumbs_up_clicked{background:green}
85
  #thumbs_down_clicked{background:red}
86
+ .elem_lora a{color: var(--body-text-color)}
87
  '''
88
 
89
  original_pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
90
 
91
  @spaces.GPU
92
  def merge_and_run(prompt, negative_prompt, shuffled_items, lora_1_scale=0.5, lora_2_scale=0.5, seed=-1, progress=gr.Progress(track_tqdm=True)):
93
+ print("Run this?")
94
  repo_id_1 = shuffled_items[0]['repo']
95
  repo_id_2 = shuffled_items[1]['repo']
96
  print("Loading state dicts...")
 
119
  def get_description(item):
120
  trigger_word = item["trigger_word"]
121
  return f"Trigger: `{trigger_word}`" if trigger_word else "No trigger, applied automatically", trigger_word
122
+
123
+
124
+ def truncate_string(s, max_length=30):
125
+ return s[:max_length - 3] + "..." if len(s) > max_length else s
126
+
127
  def shuffle_images():
128
  compatible_items = [item for item in sdxl_loras if item['is_compatible']]
129
  random.shuffle(compatible_items)
 
135
  description_1, trigger_word_1 = get_description(two_shuffled_items[0])
136
  description_2, trigger_word_2 = get_description(two_shuffled_items[1])
137
 
138
+ lora_1_link = f"[{truncate_string(two_shuffled_items[0]['repo'])}](https://huggingface.co/{two_shuffled_items[0]['repo']}) ✨"
139
+ lora_2_link = f"[{truncate_string(two_shuffled_items[1]['repo'])}](https://huggingface.co/{two_shuffled_items[1]['repo']}) ✨"
140
  prompt_description_1 = gr.update(value=description_1, visible=True)
141
  prompt_description_2 = gr.update(value=description_2, visible=True)
142
  prompt = gr.update(value=f"{trigger_word_1} {trigger_word_2}")
 
166
  with gr.Column(min_width=10, scale=16, elem_classes="plus_column"):
167
  with gr.Row():
168
  with gr.Column(min_width=10, scale=4, elem_classes="random_column"):
169
+ lora_1_link = gr.Markdown(elem_classes="title_lora")
170
  lora_1 = gr.Image(interactive=False, show_label=False, height=150, elem_classes="selected_random", elem_id="randomLoRA_1", show_share_button=False, show_download_button=False)
171
  lora_1_id = gr.Textbox(visible=False, elem_id="random_lora_1_id")
172
  lora_1_prompt = gr.Markdown(visible=False)
173
  with gr.Column(min_width=10, scale=1, elem_classes="plus_column"):
174
  plus = gr.HTML("+", elem_classes="plus_button")
175
  with gr.Column(min_width=10, scale=4, elem_classes="random_column"):
176
+ lora_2_link = gr.Markdown(elem_classes="title_lora")
177
  lora_2 = gr.Image(interactive=False, show_label=False, height=150, elem_classes="selected_random", elem_id="randomLoRA_2", show_share_button=False, show_download_button=False)
178
  lora_2_id = gr.Textbox(visible=False, elem_id="random_lora_2_id")
179
  lora_2_prompt = gr.Markdown(visible=False)