multimodalart HF staff commited on
Commit
94d6ecd
1 Parent(s): 2d94d56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
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=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
  )
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
- message = None
328
- if response_code == "409":
329
- if i < 3:
330
- user_repo_id = f"{profile.preferred_username}/{slug_name}-{i}"
331
- response_code = transfer_repos(repo_id, user_repo_id)
332
- i += 1
333
- else:
334
- message = "It seems this model has been uploaded already in your account."
335
- elif response_code == "404":
336
- message = "Something went wrong with the model upload. Try again."
337
- else:
338
- message = f"Unexpected response code: {response_code}."
339
-
340
- if message:
341
- api.delete_repo(repo_id=repo_id, repo_type="model")
342
- raise gr.Error(message)
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}) '''