| |
| """ |
| Individual model file upload script |
| Uses the successful single-file upload approach |
| """ |
|
|
| import os |
| import logging |
| from huggingface_hub import upload_file |
|
|
| |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') |
| logger = logging.getLogger(__name__) |
|
|
| def upload_individual_models(): |
| """Upload individual model files using proven method""" |
| |
| token = os.getenv('HF_TOKEN') |
| if not token: |
| raise ValueError("HF_TOKEN environment variable not set") |
| |
| |
| model_files = [] |
| experiments_path = "/data/experiments" |
| |
| if os.path.exists(experiments_path): |
| for root, _, files in os.walk(experiments_path): |
| for file in files: |
| if file.endswith(('.safetensors', '.pt', '.bin')): |
| file_path = os.path.join(root, file) |
| try: |
| file_size = os.path.getsize(file_path) |
| |
| if file_size > 10 * 1024**3: |
| logger.warning(f"Skipping extremely large file: {file_path} ({file_size/1024**3:.1f}GB)") |
| continue |
| model_files.append(file_path) |
| except OSError: |
| logger.warning(f"Could not get size for {file_path}") |
| |
| logger.info(f"Found {len(model_files)} model files to upload") |
| |
| |
| success_count = 0 |
| failed_count = 0 |
| |
| for file_path in model_files: |
| try: |
| |
| rel_path = file_path.replace('/data/experiments/', '') |
| |
| logger.info(f"Uploading: {file_path} -> LevelUp2x/dto-models/{rel_path}") |
| |
| |
| upload_file( |
| path_or_fileobj=file_path, |
| path_in_repo=rel_path, |
| repo_id='LevelUp2x/dto-models', |
| token=token, |
| commit_message=f"DTO Archive: Uploading {os.path.basename(file_path)}" |
| ) |
| |
| logger.info(f"✅ Successfully uploaded {file_path}") |
| success_count += 1 |
| |
| except Exception as e: |
| logger.error(f"❌ Failed to upload {file_path}: {e}") |
| failed_count += 1 |
| |
| logger.info(f"Upload Summary: {success_count} successful, {failed_count} failed") |
| |
| if success_count > 0: |
| logger.info("✅ Individual file upload completed successfully") |
| return True |
| else: |
| logger.error("❌ Individual file upload failed completely") |
| return False |
|
|
| if __name__ == "__main__": |
| |
| env_file = "/data/adaptai/platform/dataops/dto/.env" |
| if os.path.exists(env_file): |
| with open(env_file) as f: |
| for line in f: |
| if line.strip() and not line.startswith('#'): |
| key, value = line.strip().split('=', 1) |
| os.environ[key] = value |
| |
| upload_individual_models() |