akhaliq HF Staff commited on
Commit
68ff582
·
1 Parent(s): 6de7d1a
Files changed (1) hide show
  1. backend_deploy.py +24 -17
backend_deploy.py CHANGED
@@ -513,26 +513,33 @@ def deploy_to_huggingface_space(
513
  print(f"[Deploy] Template duplication result: {duplicated_repo} (type: {type(duplicated_repo)})")
514
  except Exception as e:
515
  print(f"[Deploy] Exception during duplicate_space: {type(e).__name__}: {str(e)}")
516
- import traceback
517
- traceback.print_exc()
518
 
519
- # Handle potential RepoUrl object errors
 
 
 
 
 
 
 
 
520
  error_msg = str(e)
521
- if "'url'" in error_msg or "RepoUrl" in error_msg:
522
- # For RepoUrl object issues, check if the space was actually created successfully
523
- print(f"[Deploy] RepoUrl error detected, checking if space was created: {error_msg}")
524
- try:
525
- # Check if space exists by trying to access it
526
- space_info = api.space_info(repo_id)
527
- if space_info:
528
- print(f"[Deploy] Space exists despite RepoUrl error, continuing with deployment")
529
- else:
530
- return False, f"Failed to create transformers.js space: {str(e)}", None
531
- except Exception as check_error:
532
- return False, f"Failed to create transformers.js space: {str(e)}", None
533
  else:
534
- # Other errors - report them
535
- return False, f"Failed to create transformers.js space: {str(e)}", None
 
 
 
 
 
 
 
 
 
 
 
536
  else:
537
  # For updates, verify we can access the existing space
538
  try:
 
513
  print(f"[Deploy] Template duplication result: {duplicated_repo} (type: {type(duplicated_repo)})")
514
  except Exception as e:
515
  print(f"[Deploy] Exception during duplicate_space: {type(e).__name__}: {str(e)}")
 
 
516
 
517
+ # Check if space actually exists (success despite error)
518
+ space_exists = False
519
+ try:
520
+ if api.space_info(repo_id):
521
+ space_exists = True
522
+ except:
523
+ pass
524
+
525
+ # Handle RepoUrl object "errors"
526
  error_msg = str(e)
527
+ if ("'url'" in error_msg or "RepoUrl" in error_msg) and space_exists:
528
+ print(f"[Deploy] Space exists despite RepoUrl error, continuing with deployment")
 
 
 
 
 
 
 
 
 
 
529
  else:
530
+ # Fallback to regular create_repo
531
+ print(f"[Deploy] Template duplication failed, attempting fallback to create_repo: {e}")
532
+ try:
533
+ api.create_repo(
534
+ repo_id=repo_id,
535
+ repo_type="space",
536
+ space_sdk="static",
537
+ private=private,
538
+ exist_ok=True
539
+ )
540
+ print(f"[Deploy] Fallback create_repo successful")
541
+ except Exception as e2:
542
+ return False, f"Failed to create transformers.js space (both duplication and fallback failed): {str(e2)}", None
543
  else:
544
  # For updates, verify we can access the existing space
545
  try: