John6666 commited on
Commit
55d77a8
·
verified ·
1 Parent(s): 7fd0b6a

Upload StableGR.py

Browse files

Parsing and error handling have been added to the download.

Files changed (1) hide show
  1. StableGR.py +11 -5
StableGR.py CHANGED
@@ -19,7 +19,6 @@ from stablepy import Model_Diffusers
19
 
20
  TEMP_DIR = os.getcwd()
21
 
22
-
23
  def parse_urls(s):
24
  url_pattern = "https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+"
25
  try:
@@ -66,10 +65,17 @@ def generate_image(model_id, prompt, lora_A, num_steps, guidance_scale, sampler,
66
 
67
 
68
  def download_file(dl_url, civitai_key, progress=gr.Progress(track_tqdm=True)):
69
- download_dir = TEMP_DIR
70
- progress(0, desc=f"Start downloading... {dl_url}")
71
- output_filename = get_download_file(download_dir, dl_url, civitai_key)
72
- return output_filename
 
 
 
 
 
 
 
73
 
74
 
75
  def save_civitai_info(dl_url, filename, civitai_key="", progress=gr.Progress(track_tqdm=True)):
 
19
 
20
  TEMP_DIR = os.getcwd()
21
 
 
22
  def parse_urls(s):
23
  url_pattern = "https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+"
24
  try:
 
65
 
66
 
67
  def download_file(dl_url, civitai_key, progress=gr.Progress(track_tqdm=True)):
68
+ try:
69
+ download_dir = TEMP_DIR
70
+ progress(0, desc=f"Start downloading... {dl_url}")
71
+ dl_urls = parse_urls(dl_url)
72
+ if len(dl_urls) == 0: raise Exception(f"Invalid or empty URL: {dl_url}")
73
+ output_filename = get_download_file(download_dir, dl_urls[0], civitai_key)
74
+ if not output_filename: raise Exception(f"Failed to download: {dl_urls[0]}")
75
+ return output_filename
76
+ except Exception as e:
77
+ print(e)
78
+ return gr.update()
79
 
80
 
81
  def save_civitai_info(dl_url, filename, civitai_key="", progress=gr.Progress(track_tqdm=True)):