Spaces:
Running
Running
Commit
•
94d6ecd
1
Parent(s):
2d94d56
Update app.py
Browse files
app.py
CHANGED
@@ -289,7 +289,7 @@ def list_civit_models(username):
|
|
289 |
|
290 |
return urls
|
291 |
|
292 |
-
def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, link_civit=False, progress=gr.Progress(track_tqdm=True)):
|
293 |
if not profile.name:
|
294 |
return gr.Error("Are you sure you are logged in?")
|
295 |
|
@@ -305,41 +305,42 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, link_civit=False
|
|
305 |
user_repo_id = f"{profile.preferred_username}/{slug_name}"
|
306 |
create_readme(info, downloaded_files, user_repo_id, link_civit, folder=folder)
|
307 |
try:
|
308 |
-
repo_id = f"{username}/{profile.preferred_username}-{slug_name}"
|
309 |
print("Creating repo...")
|
310 |
-
api.create_repo(repo_id=
|
311 |
print("Uploading repo...")
|
312 |
api.upload_folder(
|
313 |
folder_path=folder,
|
314 |
repo_id=repo_id,
|
315 |
repo_type="model",
|
|
|
316 |
)
|
317 |
print("Changing repo visibility...")
|
318 |
api.update_repo_visibility(repo_id=repo_id, private=False)
|
319 |
except:
|
320 |
raise gr.Error("uploading the repo went wrong")
|
321 |
|
322 |
-
transfer_repos = gr.load("multimodalart/transfer_repos", hf_token=os.environ["HUGGING_FACE_HUB_TOKEN"], src="spaces")
|
323 |
|
324 |
-
response_code = transfer_repos(repo_id, user_repo_id)
|
325 |
-
i = 0
|
326 |
-
while response_code != "200":
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
|
344 |
return f'''# Model uploaded to 🤗!
|
345 |
## Access it here [{user_repo_id}](https://huggingface.co/{user_repo_id}) '''
|
|
|
289 |
|
290 |
return urls
|
291 |
|
292 |
+
def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], oauth_token: gr.OAuthToken, url, link_civit=False, progress=gr.Progress(track_tqdm=True)):
|
293 |
if not profile.name:
|
294 |
return gr.Error("Are you sure you are logged in?")
|
295 |
|
|
|
305 |
user_repo_id = f"{profile.preferred_username}/{slug_name}"
|
306 |
create_readme(info, downloaded_files, user_repo_id, link_civit, folder=folder)
|
307 |
try:
|
308 |
+
#repo_id = f"{username}/{profile.preferred_username}-{slug_name}"
|
309 |
print("Creating repo...")
|
310 |
+
api.create_repo(repo_id=user_repo_id, private=True, exist_ok=True)
|
311 |
print("Uploading repo...")
|
312 |
api.upload_folder(
|
313 |
folder_path=folder,
|
314 |
repo_id=repo_id,
|
315 |
repo_type="model",
|
316 |
+
token=oauth_token,
|
317 |
)
|
318 |
print("Changing repo visibility...")
|
319 |
api.update_repo_visibility(repo_id=repo_id, private=False)
|
320 |
except:
|
321 |
raise gr.Error("uploading the repo went wrong")
|
322 |
|
323 |
+
#transfer_repos = gr.load("multimodalart/transfer_repos", hf_token=os.environ["HUGGING_FACE_HUB_TOKEN"], src="spaces")
|
324 |
|
325 |
+
#response_code = transfer_repos(repo_id, user_repo_id)
|
326 |
+
#i = 0
|
327 |
+
#while response_code != "200":
|
328 |
+
# message = None
|
329 |
+
# if response_code == "409":
|
330 |
+
# if i < 3:
|
331 |
+
# user_repo_id = f"{profile.preferred_username}/{slug_name}-{i}"
|
332 |
+
# response_code = transfer_repos(repo_id, user_repo_id)
|
333 |
+
# i += 1
|
334 |
+
# else:
|
335 |
+
# message = "It seems this model has been uploaded already in your account."
|
336 |
+
# elif response_code == "404":
|
337 |
+
# message = "Something went wrong with the model upload. Try again."
|
338 |
+
# else:
|
339 |
+
# message = f"Unexpected response code: {response_code}."
|
340 |
+
#
|
341 |
+
# if message:
|
342 |
+
# api.delete_repo(repo_id=repo_id, repo_type="model")
|
343 |
+
# raise gr.Error(message)
|
344 |
|
345 |
return f'''# Model uploaded to 🤗!
|
346 |
## Access it here [{user_repo_id}](https://huggingface.co/{user_repo_id}) '''
|