r3gm commited on
Commit
66165d4
·
verified ·
1 Parent(s): f769a93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -75,7 +75,7 @@ import diffusers
75
  import warnings
76
  from stablepy import logger
77
  from diffusers import FluxPipeline
78
- # import urllib.parse
79
  import subprocess
80
 
81
  os.system("pip list")
@@ -246,13 +246,13 @@ class GuiSD:
246
  self.active_downloads.add(lock_key)
247
  break
248
 
249
- yield f"Waiting for existing download to finish: {model_name}..."
250
  time.sleep(1)
251
 
252
  try:
253
  # download link model > model_name
254
  if model_name.startswith("http"):
255
- yield f"Downloading model: {model_name}"
256
  model_name = download_things(DIRECTORY_MODELS, model_name, HF_TOKEN, CIVITAI_API_KEY)
257
  if not model_name:
258
  raise ValueError("Error retrieving model information from URL")
@@ -294,7 +294,7 @@ class GuiSD:
294
 
295
  self.status_loading = True
296
 
297
- yield f"Loading model: {model_name}"
298
 
299
  if vae_model == "BakedVAE":
300
  vae_model = model_name
@@ -351,7 +351,7 @@ class GuiSD:
351
  self.last_load = datetime.now()
352
  self.status_loading = False
353
 
354
- yield f"Model loaded: {model_name}"
355
 
356
  # @spaces.GPU(duration=59)
357
  @torch.inference_mode()
@@ -481,7 +481,7 @@ class GuiSD:
481
 
482
  vae_model = vae_model if vae_model != "None" else None
483
  loras_list = [lora1, lora2, lora3, lora4, lora5, lora6, lora7]
484
- vae_msg = f"VAE: {vae_model}" if vae_model else ""
485
  msg_lora = ""
486
 
487
  logger.debug(f"Config model: {model_name}, {vae_model}, {loras_list}")
@@ -675,9 +675,9 @@ class GuiSD:
675
 
676
  for status, lora in zip(self.model.lora_status, self.model.lora_memory):
677
  if status:
678
- msg_lora += f"<br>Loaded: {lora}"
679
  elif status is not None:
680
- msg_lora += f"<br>Error with: {lora}"
681
 
682
  if msg_lora:
683
  info_images += msg_lora
@@ -686,7 +686,7 @@ class GuiSD:
686
 
687
  download_links = "<br>".join(
688
  [
689
- f'<a href="{path.replace("/images/", f"/gradio_api/file={allowed_path}/")}" download="{os.path.basename(path)}">Download Image {i + 1}</a>'
690
  for i, path in enumerate(image_path)
691
  ]
692
  )
@@ -770,7 +770,7 @@ def sd_gen_generate_pipeline(*args):
770
  )
771
  gr.Info(f"LoRAs in cache: {lora_cache_msg}")
772
 
773
- msg_request = f"Requesting {gpu_duration_arg}s. of GPU time.\nModel: {sd_gen.model.base_model_id}"
774
  if verbose_arg:
775
  gr.Info(msg_request)
776
  print(msg_request)
@@ -935,6 +935,7 @@ with gr.Blocks(fill_width=True, fill_height=False) as app:
935
  "Image resolution": gr.update(value=1024),
936
  "Strength": gr.update(),
937
  "Prompt emphasis": gr.update(),
 
938
  }
939
 
940
  # Generate up to 7 LoRAs
@@ -1027,6 +1028,15 @@ with gr.Blocks(fill_width=True, fill_height=False) as app:
1027
  val = filtered_models[0]
1028
  else:
1029
  val = name_model
 
 
 
 
 
 
 
 
 
1030
  if key == "Hires upscaler":
1031
  if val not in UPSCALER_KEYS:
1032
  continue
@@ -1187,7 +1197,7 @@ with gr.Blocks(fill_width=True, fill_height=False) as app:
1187
  label="Style Prompt",
1188
  interactive=True,
1189
  )
1190
- style_json_gui = gr.File(label="Style JSON File")
1191
  style_button = gr.Button("Load styles")
1192
 
1193
  def load_json_style_file(json):
@@ -1290,6 +1300,7 @@ with gr.Blocks(fill_width=True, fill_height=False) as app:
1290
  image_resolution_gui,
1291
  strength_gui,
1292
  prompt_syntax_gui,
 
1293
  lora1_gui,
1294
  lora_scale_1_gui,
1295
  lora2_gui,
 
75
  import warnings
76
  from stablepy import logger
77
  from diffusers import FluxPipeline
78
+ import urllib.parse
79
  import subprocess
80
 
81
  os.system("pip list")
 
246
  self.active_downloads.add(lock_key)
247
  break
248
 
249
+ yield f"Waiting for existing download to finish: {escape_html(model_name)}..."
250
  time.sleep(1)
251
 
252
  try:
253
  # download link model > model_name
254
  if model_name.startswith("http"):
255
+ yield f"Downloading model: {escape_html(model_name)}"
256
  model_name = download_things(DIRECTORY_MODELS, model_name, HF_TOKEN, CIVITAI_API_KEY)
257
  if not model_name:
258
  raise ValueError("Error retrieving model information from URL")
 
294
 
295
  self.status_loading = True
296
 
297
+ yield f"Loading model: {escape_html(model_name)}"
298
 
299
  if vae_model == "BakedVAE":
300
  vae_model = model_name
 
351
  self.last_load = datetime.now()
352
  self.status_loading = False
353
 
354
+ yield f"Model loaded: {escape_html(model_name)}"
355
 
356
  # @spaces.GPU(duration=59)
357
  @torch.inference_mode()
 
481
 
482
  vae_model = vae_model if vae_model != "None" else None
483
  loras_list = [lora1, lora2, lora3, lora4, lora5, lora6, lora7]
484
+ vae_msg = f"VAE: {escape_html(vae_model)}" if vae_model else ""
485
  msg_lora = ""
486
 
487
  logger.debug(f"Config model: {model_name}, {vae_model}, {loras_list}")
 
675
 
676
  for status, lora in zip(self.model.lora_status, self.model.lora_memory):
677
  if status:
678
+ msg_lora += f"<br>Loaded: {escape_html(lora)}"
679
  elif status is not None:
680
+ msg_lora += f"<br>Error with: {escape_html(lora)}"
681
 
682
  if msg_lora:
683
  info_images += msg_lora
 
686
 
687
  download_links = "<br>".join(
688
  [
689
+ f'<a href="{path.replace("/images/", f"/gradio_api/file={allowed_path}/")}" download="{escape_html(os.path.basename(path))}">Download Image {i + 1}</a>'
690
  for i, path in enumerate(image_path)
691
  ]
692
  )
 
770
  )
771
  gr.Info(f"LoRAs in cache: {lora_cache_msg}")
772
 
773
+ msg_request = f"Requesting {gpu_duration_arg}s. of GPU time.\nModel: {escape_html(sd_gen.model.base_model_id)}"
774
  if verbose_arg:
775
  gr.Info(msg_request)
776
  print(msg_request)
 
935
  "Image resolution": gr.update(value=1024),
936
  "Strength": gr.update(),
937
  "Prompt emphasis": gr.update(),
938
+ "VAE": gr.update(),
939
  }
940
 
941
  # Generate up to 7 LoRAs
 
1028
  val = filtered_models[0]
1029
  else:
1030
  val = name_model
1031
+ if key == "VAE":
1032
+ val_unquote = urllib.parse.unquote(str(val))
1033
+ filtered_vaes = [v for v in vae_model_list if str(val) in v or val_unquote in v]
1034
+ if filtered_vaes:
1035
+ val = filtered_vaes[0]
1036
+ elif val in ["None", "BakedVAE"]:
1037
+ val = val
1038
+ else:
1039
+ continue
1040
  if key == "Hires upscaler":
1041
  if val not in UPSCALER_KEYS:
1042
  continue
 
1197
  label="Style Prompt",
1198
  interactive=True,
1199
  )
1200
+ style_json_gui = gr.File(label="Style JSON File", file_count="single", file_types=[".json"])
1201
  style_button = gr.Button("Load styles")
1202
 
1203
  def load_json_style_file(json):
 
1300
  image_resolution_gui,
1301
  strength_gui,
1302
  prompt_syntax_gui,
1303
+ vae_model_gui,
1304
  lora1_gui,
1305
  lora_scale_1_gui,
1306
  lora2_gui,