take out HF_TOKEN
#1
by Cunt1257 - opened
- cunt1257/pussymagnet1 +137 -0
cunt1257/pussymagnet1
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Here's a clean, production-ready solution to **auto-deploy your Hugging Face model** using the provided credentials. This includes:
|
| 2 |
+
|
| 3 |
+
β
Auto-login with HF token
|
| 4 |
+
β
Git clone + LFS skip (for large files)
|
| 5 |
+
β
Model upload via `transformers` + `huggingface_hub`
|
| 6 |
+
β
Auto-deployment to a **new public space** (we'll use `hf.co/spaces`)
|
| 7 |
+
β
Error handling & logging
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## β
1. Install Dependencies
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
pip install transformers huggingface_hub torch accelerate tqdm
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
> π‘ Note: If you're running on a server or cloud (like AWS/GCP), make sure you have `pip` installed.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## β
2. Create the Deployment Script (`deploy_hf.py`)
|
| 22 |
+
|
| 23 |
+
```python
|
| 24 |
+
#!/usr/bin/env python3
|
| 25 |
+
# -*- coding: utf-8 -*-
|
| 26 |
+
"""
|
| 27 |
+
Auto-deploy script for Hugging Face Spaces from GitHub repo.
|
| 28 |
+
Uses HF token for authentication and uploads model to new space.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
import os
|
| 32 |
+
import subprocess
|
| 33 |
+
import sys
|
| 34 |
+
from datetime import datetime
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
import logging
|
| 37 |
+
|
| 38 |
+
# Configure logging
|
| 39 |
+
logging.basicConfig(
|
| 40 |
+
level=logging.INFO,
|
| 41 |
+
format='%(asctime)s [%(levelname)s] %(message)s',
|
| 42 |
+
handlers=[
|
| 43 |
+
logging.FileHandler("deploy.log"),
|
| 44 |
+
logging.StreamHandler(sys.stdout)
|
| 45 |
+
]
|
| 46 |
+
)
|
| 47 |
+
logger = logging.getLogger(__name__)
|
| 48 |
+
|
| 49 |
+
# Configuration
|
| 50 |
+
HF_USER = "cunt1257"
|
| 51 |
+
HF_PASS = "Newlife1257" # You can store this in .env file securely
|
| 52 |
+
HF_TOKEN = "" # From your prompt
|
| 53 |
+
|
| 54 |
+
REPO_URL = "https://huggingface.co/Cunt1257/pussymagnet"
|
| 55 |
+
SPACE_NAME = "nwa-auto-auction-space" # Suggested name for clarity
|
| 56 |
+
MODEL_NAME = "pussymagnet" # The model name on HF
|
| 57 |
+
|
| 58 |
+
# Optional: Use environment variables instead of hardcoding
|
| 59 |
+
def get_token():
|
| 60 |
+
if HF_TOKEN:
|
| 61 |
+
return HF_TOKEN
|
| 62 |
+
else:
|
| 63 |
+
raise ValueError("HF_TOKEN not set. Please provide valid HF token.")
|
| 64 |
+
|
| 65 |
+
def login_to_hf(token):
|
| 66 |
+
"""Login to Hugging Face CLI"""
|
| 67 |
+
try:
|
| 68 |
+
logger.info(f"Logging into Hugging Face with token...")
|
| 69 |
+
result = subprocess.run([
|
| 70 |
+
"hf", "login",
|
| 71 |
+
"-u", HF_USER,
|
| 72 |
+
"-p", HF_PASS
|
| 73 |
+
], capture_output=True, text=True)
|
| 74 |
+
if result.returncode != 0:
|
| 75 |
+
logger.error(f"Failed to login: {result.stderr}")
|
| 76 |
+
raise Exception("Login failed")
|
| 77 |
+
logger.info("Login successful.")
|
| 78 |
+
except Exception as e:
|
| 79 |
+
logger.error(f"Error during login: {e}")
|
| 80 |
+
|
| 81 |
+
def clone_repo(repo_url, target_dir="pussymagnet"):
|
| 82 |
+
"""Clone repository with LFS skipping"""
|
| 83 |
+
logger.info(f"Cloning {repo_url} to {target_dir}...")
|
| 84 |
+
try:
|
| 85 |
+
# Clone without LFS (to avoid issues with large files)
|
| 86 |
+
cmd = f"git clone --no-checkout {repo_url} {target_dir}"
|
| 87 |
+
result = subprocess.run(cmd.split(), capture_output=True, text=True)
|
| 88 |
+
if result.returncode != 0:
|
| 89 |
+
logger.error(f"Git clone failed:\n{result.stderr}")
|
| 90 |
+
raise Exception("Clone failed")
|
| 91 |
+
|
| 92 |
+
# Initialize submodules if needed (optional)
|
| 93 |
+
# subprocess.run(["git", "submodule", "update", "--init"], cwd=target_dir, check=True)
|
| 94 |
+
|
| 95 |
+
logger.info("Repository cloned successfully.")
|
| 96 |
+
return target_dir
|
| 97 |
+
except Exception as e:
|
| 98 |
+
logger.error(f"Error cloning repo: {e}")
|
| 99 |
+
raise
|
| 100 |
+
|
| 101 |
+
def push_model_to_space(model_path, space_name, token=None):
|
| 102 |
+
"""Upload model to Hugging Face Space"""
|
| 103 |
+
try:
|
| 104 |
+
logger.info(f"Uploading model to HF Space: {space_name}")
|
| 105 |
+
|
| 106 |
+
# Set up local directory structure for uploading
|
| 107 |
+
from huggingface_hub import create_repo, upload_file
|
| 108 |
+
|
| 109 |
+
# Create repo if doesn't exist
|
| 110 |
+
repo_id = f"{HF_USER}/{space_name}" # Format: user/repo-name
|
| 111 |
+
|
| 112 |
+
# Create repo (if not exists)
|
| 113 |
+
create_repo(
|
| 114 |
+
repo_id=repo_id,
|
| 115 |
+
private=False,
|
| 116 |
+
exist_ok=True,
|
| 117 |
+
token=token
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# Upload model files
|
| 121 |
+
model_files = [
|
| 122 |
+
".",
|
| 123 |
+
"README.md",
|
| 124 |
+
"LICENSE",
|
| 125 |
+
"requirements.txt"
|
| 126 |
+
]
|
| 127 |
+
|
| 128 |
+
# Upload all files recursively (you may want to filter only specific ones)
|
| 129 |
+
for item in Path(model_path).rglob("*"):
|
| 130 |
+
if item.is_file():
|
| 131 |
+
relative_path = str(item.relative_to(model_path))
|
| 132 |
+
upload_file(
|
| 133 |
+
path_or_obj=item,
|
| 134 |
+
repo_id=repo_id,
|
| 135 |
+
commit_message=f"Deployed at {datetime.now().strftime('%Y-%m-%d %H:%M')}",
|
| 136 |
+
token=token
|
| 137 |
+
|