Spaces:
Running
Running
Upload utils.py
Browse files
utils.py
CHANGED
@@ -151,7 +151,7 @@ def download_thing(directory, url, civitai_api_key="", progress=gr.Progress(trac
|
|
151 |
|
152 |
def get_local_file_list(dir_path):
|
153 |
file_list = []
|
154 |
-
for file in Path(dir_path).glob("
|
155 |
if file.is_file():
|
156 |
file_path = str(file)
|
157 |
file_list.append(file_path)
|
@@ -197,17 +197,13 @@ def download_repo(repo_id: str, dir_path: str, progress=gr.Progress(track_tqdm=T
|
|
197 |
return False
|
198 |
|
199 |
|
200 |
-
def upload_repo(repo_id: str, dir_path: str, is_private: bool, progress=gr.Progress(track_tqdm=True)): # for diffusers repo
|
201 |
hf_token = get_token()
|
202 |
api = HfApi(token=hf_token)
|
203 |
try:
|
204 |
progress(0, desc="Start uploading...")
|
205 |
api.create_repo(repo_id=repo_id, token=hf_token, private=is_private, exist_ok=True)
|
206 |
-
|
207 |
-
if path.is_dir():
|
208 |
-
api.upload_folder(repo_id=repo_id, folder_path=str(path), path_in_repo=path.name, token=hf_token)
|
209 |
-
elif path.is_file():
|
210 |
-
api.upload_file(repo_id=repo_id, path_or_fileobj=str(path), path_in_repo=path.name, token=hf_token)
|
211 |
progress(1, desc="Uploaded.")
|
212 |
return get_hf_url(repo_id, "model")
|
213 |
except Exception as e:
|
@@ -215,6 +211,18 @@ def upload_repo(repo_id: str, dir_path: str, is_private: bool, progress=gr.Progr
|
|
215 |
return ""
|
216 |
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
HF_SUBFOLDER_NAME = ["None", "user_repo"]
|
219 |
|
220 |
|
|
|
151 |
|
152 |
def get_local_file_list(dir_path):
|
153 |
file_list = []
|
154 |
+
for file in Path(dir_path).glob("*/*.*"):
|
155 |
if file.is_file():
|
156 |
file_path = str(file)
|
157 |
file_list.append(file_path)
|
|
|
197 |
return False
|
198 |
|
199 |
|
200 |
+
def upload_repo(repo_id: str, dir_path: str, is_private: bool, is_pr: bool=False, progress=gr.Progress(track_tqdm=True)): # for diffusers repo
|
201 |
hf_token = get_token()
|
202 |
api = HfApi(token=hf_token)
|
203 |
try:
|
204 |
progress(0, desc="Start uploading...")
|
205 |
api.create_repo(repo_id=repo_id, token=hf_token, private=is_private, exist_ok=True)
|
206 |
+
api.upload_folder(repo_id=repo_id, folder_path=dir_path, path_in_repo="", create_pr=is_pr, token=hf_token)
|
|
|
|
|
|
|
|
|
207 |
progress(1, desc="Uploaded.")
|
208 |
return get_hf_url(repo_id, "model")
|
209 |
except Exception as e:
|
|
|
211 |
return ""
|
212 |
|
213 |
|
214 |
+
def gate_repo(repo_id: str, gated_str: str, repo_type: str="model"):
|
215 |
+
hf_token = get_token()
|
216 |
+
api = HfApi(token=hf_token)
|
217 |
+
try:
|
218 |
+
if gated_str == "auto": gated = "auto"
|
219 |
+
elif gated_str == "manual": gated = "manual"
|
220 |
+
else: gated = False
|
221 |
+
api.update_repo_settings(repo_id=repo_id, gated=gated, repo_type=repo_type, token=hf_token)
|
222 |
+
except Exception as e:
|
223 |
+
print(f"Error: Failed to update settings {repo_id}. {e}")
|
224 |
+
|
225 |
+
|
226 |
HF_SUBFOLDER_NAME = ["None", "user_repo"]
|
227 |
|
228 |
|