Spaces:
Running
on
Zero
Running
on
Zero
Upload modutils.py
Browse files- modutils.py +13 -4
modutils.py
CHANGED
@@ -90,6 +90,7 @@ def get_private_model_list(repo_id, dir_path):
|
|
90 |
try:
|
91 |
files = api.list_repo_files(repo_id, token=hf_read_token)
|
92 |
except Exception as e:
|
|
|
93 |
return []
|
94 |
model_list = []
|
95 |
for file in files:
|
@@ -116,6 +117,9 @@ def get_private_lora_model_lists():
|
|
116 |
return models
|
117 |
|
118 |
|
|
|
|
|
|
|
119 |
def download_private_file(repo_id, path, is_replace):
|
120 |
from huggingface_hub import hf_hub_download
|
121 |
file = Path(path)
|
@@ -126,6 +130,7 @@ def download_private_file(repo_id, path, is_replace):
|
|
126 |
try:
|
127 |
hf_hub_download(repo_id=repo_id, filename=filename, local_dir=dirname, use_auth_token=hf_read_token)
|
128 |
except Exception as e:
|
|
|
129 |
return
|
130 |
if is_replace:
|
131 |
file.resolve().rename(newpath.resolve())
|
@@ -229,10 +234,14 @@ def save_gallery_images(images, progress=gr.Progress(track_tqdm=True)):
|
|
229 |
i += 1
|
230 |
oldpath = Path(image[0])
|
231 |
newpath = oldpath
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
236 |
progress(1, desc="Gallery updated.")
|
237 |
return gr.update(value=output_images), gr.update(value=output_paths), gr.update(visible=True)
|
238 |
|
|
|
90 |
try:
|
91 |
files = api.list_repo_files(repo_id, token=hf_read_token)
|
92 |
except Exception as e:
|
93 |
+
print(f"Error: Failed to list {repo_id}. ")
|
94 |
return []
|
95 |
model_list = []
|
96 |
for file in files:
|
|
|
117 |
return models
|
118 |
|
119 |
|
120 |
+
private_lora_model_list = get_private_lora_model_lists()
|
121 |
+
|
122 |
+
|
123 |
def download_private_file(repo_id, path, is_replace):
|
124 |
from huggingface_hub import hf_hub_download
|
125 |
file = Path(path)
|
|
|
130 |
try:
|
131 |
hf_hub_download(repo_id=repo_id, filename=filename, local_dir=dirname, use_auth_token=hf_read_token)
|
132 |
except Exception as e:
|
133 |
+
print(f"Error: Failed to download {filename}. ")
|
134 |
return
|
135 |
if is_replace:
|
136 |
file.resolve().rename(newpath.resolve())
|
|
|
234 |
i += 1
|
235 |
oldpath = Path(image[0])
|
236 |
newpath = oldpath
|
237 |
+
try:
|
238 |
+
if oldpath.exists():
|
239 |
+
newpath = oldpath.resolve().rename(Path(filename).resolve())
|
240 |
+
except Exception:
|
241 |
+
pass
|
242 |
+
finally:
|
243 |
+
output_paths.append(str(newpath))
|
244 |
+
output_images.append((str(newpath), str(filename)))
|
245 |
progress(1, desc="Gallery updated.")
|
246 |
return gr.update(value=output_images), gr.update(value=output_paths), gr.update(visible=True)
|
247 |
|