Joseph Pollack commited on
Commit
c9c4ddf
Β·
unverified Β·
1 Parent(s): 7cafe2c

adds datasets repo name and simplifies repo ceration

Browse files
Files changed (1) hide show
  1. scripts/deploy_demo_space.py +53 -36
scripts/deploy_demo_space.py CHANGED
@@ -480,31 +480,42 @@ os.environ['BRAND_PROJECT_URL'] = json.dumps({_json.dumps(self.brand_project_url
480
  # Set HF token for CLI
481
  os.environ['HF_TOKEN'] = self.hf_token
482
 
483
- # Create space using Hugging Face CLI
484
- cmd = [
485
- "hf", "repo", "create",
486
- self.space_id,
487
- "--type", "space"
 
488
  ]
489
-
490
- logger.info(f"Running command: {' '.join(cmd)}")
491
- result = subprocess.run(cmd, capture_output=True, text=True)
492
-
493
- if result.returncode != 0:
494
- logger.warning(f"First attempt failed: {result.stderr}")
495
- # Try alternative approach without space-specific flags
496
- logger.info("Retrying with basic space creation...")
497
- cmd = [
498
- "hf", "repo", "create",
499
- self.space_id
500
- ]
501
  result = subprocess.run(cmd, capture_output=True, text=True)
502
-
503
- if result.returncode == 0:
504
- logger.info(f"βœ… Space created successfully: {self.space_url}")
505
- return True
 
 
506
  else:
507
- logger.error(f"❌ Failed to create space: {result.stderr}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
508
  return False
509
 
510
  except Exception as e:
@@ -626,20 +637,26 @@ os.environ['BRAND_PROJECT_URL'] = json.dumps({_json.dumps(self.brand_project_url
626
 
627
  for file_path in temp_path.iterdir():
628
  if file_path.is_file():
629
- try:
630
- # Upload file to the space
631
- upload_file(
632
- path_or_fileobj=str(file_path),
633
- path_in_repo=file_path.name,
634
- repo_id=self.space_id,
635
- repo_type="space",
636
- token=self.hf_token
637
- )
638
- uploaded_files.append(file_path.name)
639
- logger.info(f"βœ… Uploaded {file_path.name}")
640
- except Exception as e:
641
- logger.error(f"❌ Failed to upload {file_path.name}: {e}")
642
- return False
 
 
 
 
 
 
643
 
644
  logger.info(f"βœ… Successfully uploaded {len(uploaded_files)} files to Space")
645
  return True
 
480
  # Set HF token for CLI
481
  os.environ['HF_TOKEN'] = self.hf_token
482
 
483
+ # Try multiple CLI variants depending on installed version
484
+ cli_attempts = [
485
+ ["hf", "space", "create", self.space_id, "--type", "gradio", "--hardware", "cpu-basic"],
486
+ ["huggingface-cli", "space", "create", self.space_id, "--type", "gradio", "--hardware", "cpu-basic"],
487
+ ["hf", "repo", "create", self.space_id, "--repo-type", "space"],
488
+ ["huggingface-cli", "repo", "create", self.space_id, "--repo-type", "space"],
489
  ]
490
+
491
+ last_err = None
492
+ for cmd in cli_attempts:
493
+ logger.info(f"Running command: {' '.join(cmd)}")
 
 
 
 
 
 
 
 
494
  result = subprocess.run(cmd, capture_output=True, text=True)
495
+ if result.returncode == 0:
496
+ logger.info(f"βœ… Space created (CLI): {self.space_url}")
497
+ break
498
+ else:
499
+ last_err = result.stderr
500
+ logger.warning(f"CLI attempt failed: {last_err}")
501
  else:
502
+ logger.error(f"❌ Failed to create space via CLI: {last_err}")
503
+ return False
504
+
505
+ # Verify the space exists and is recognized as a space
506
+ try:
507
+ for _ in range(10):
508
+ try:
509
+ info = self.api.repo_info(self.space_id, repo_type="space")
510
+ if info: # type: ignore
511
+ logger.info("βœ… Verified space existence via API")
512
+ return True
513
+ except Exception:
514
+ time.sleep(2)
515
+ logger.error("❌ Space verification timed out after CLI creation")
516
+ return False
517
+ except Exception as e:
518
+ logger.error(f"❌ Error verifying space: {e}")
519
  return False
520
 
521
  except Exception as e:
 
637
 
638
  for file_path in temp_path.iterdir():
639
  if file_path.is_file():
640
+ # Retry uploads to absorb propagation delays
641
+ for attempt in range(5):
642
+ try:
643
+ upload_file(
644
+ path_or_fileobj=str(file_path),
645
+ path_in_repo=file_path.name,
646
+ repo_id=self.space_id,
647
+ repo_type="space",
648
+ token=self.hf_token
649
+ )
650
+ uploaded_files.append(file_path.name)
651
+ logger.info(f"βœ… Uploaded {file_path.name}")
652
+ break
653
+ except Exception as e:
654
+ if "404" in str(e) or "Not Found" in str(e):
655
+ logger.warning(f"Upload failed (likely propagation). Retry {attempt+1}/5 in 2s: {e}")
656
+ time.sleep(2)
657
+ continue
658
+ logger.error(f"❌ Failed to upload {file_path.name}: {e}")
659
+ return False
660
 
661
  logger.info(f"βœ… Successfully uploaded {len(uploaded_files)} files to Space")
662
  return True