Spaces:
Build error
Build error
File size: 6,613 Bytes
298d6c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
#!/usr/bin/env python3
"""
Script to push Textilindo AI Assistant to Hugging Face Spaces
"""
import os
import sys
import subprocess
import shutil
from pathlib import Path
def check_git_status():
"""Check git status and setup"""
print("π Checking Git status...")
try:
# Check if we're in a git repository
result = subprocess.run(["git", "status"], capture_output=True, text=True)
if result.returncode != 0:
print("β Not in a git repository. Initializing...")
subprocess.run(["git", "init"], check=True)
print("β
Git repository initialized")
else:
print("β
Git repository found")
return True
except subprocess.CalledProcessError as e:
print(f"β Git error: {e}")
return False
except FileNotFoundError:
print("β Git not found. Please install git.")
return False
def setup_git_lfs():
"""Setup Git LFS for large files"""
print("π Setting up Git LFS...")
try:
# Install Git LFS
subprocess.run(["git", "lfs", "install"], check=True)
print("β
Git LFS installed")
# Create .gitattributes for LFS
gitattributes = """
# Large model files
*.bin filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.hdf5 filter=lfs diff=lfs merge=lfs -text
*.tar.gz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
"""
with open(".gitattributes", "w") as f:
f.write(gitattributes.strip())
print("β
.gitattributes created")
return True
except subprocess.CalledProcessError as e:
print(f"β Git LFS setup failed: {e}")
return False
def create_gitignore():
"""Create comprehensive .gitignore"""
print("π Creating .gitignore...")
gitignore_content = """
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# Virtual environments
venv/
env/
ENV/
.venv/
# IDE
.vscode/
.idea/
*.swp
*.swo
*.sublime-*
# OS
.DS_Store
Thumbs.db
*.tmp
*.temp
# Model files (use LFS for these)
models/
*.bin
*.safetensors
*.pt
*.pth
*.ckpt
# Cache
.cache/
__pycache__/
transformers_cache/
.huggingface/
# Logs
*.log
logs/
wandb/
# Environment variables
.env
.env.local
.env.production
.env.staging
# Jupyter
.ipynb_checkpoints/
# PyTorch
*.pth
*.pt
# Data files (use LFS for large ones)
data/*.jsonl
data/*.json
data/*.csv
data/*.parquet
"""
with open(".gitignore", "w") as f:
f.write(gitignore_content.strip())
print("β
.gitignore created")
def prepare_dockerfile():
"""Ensure we're using the correct Dockerfile"""
print("π³ Preparing Dockerfile...")
# Copy the HF Spaces Dockerfile to the root
if Path("Dockerfile_hf_spaces").exists():
shutil.copy("Dockerfile_hf_spaces", "Dockerfile")
print("β
Dockerfile prepared for HF Spaces")
return True
else:
print("β Dockerfile_hf_spaces not found")
return False
def create_space_config():
"""Create Hugging Face Space configuration"""
print("βοΈ Creating Space configuration...")
# Create .huggingface directory
hf_dir = Path(".huggingface")
hf_dir.mkdir(exist_ok=True)
# Create space configuration
space_config = {
"title": "Textilindo AI Assistant",
"emoji": "π€",
"colorFrom": "blue",
"colorTo": "purple",
"sdk": "docker",
"pinned": False,
"license": "mit",
"app_port": 7860,
"hardware": "gpu-basic"
}
# Write to README.md frontmatter (already done above)
print("β
Space configuration ready")
def commit_and_push():
"""Commit and push to repository"""
print("π€ Committing and pushing...")
try:
# Add all files
subprocess.run(["git", "add", "."], check=True)
print("β
Files staged")
# Commit
commit_message = "Initial commit: Textilindo AI Assistant for HF Spaces"
subprocess.run(["git", "commit", "-m", commit_message], check=True)
print("β
Changes committed")
# Check if remote exists
result = subprocess.run(["git", "remote", "-v"], capture_output=True, text=True)
if not result.stdout.strip():
print("β οΈ No remote repository found.")
print("Please add your Hugging Face Space repository as remote:")
print("git remote add origin https://huggingface.co/spaces/your-username/your-space-name")
return False
# Push to remote
subprocess.run(["git", "push", "origin", "main"], check=True)
print("β
Pushed to remote repository")
return True
except subprocess.CalledProcessError as e:
print(f"β Git operation failed: {e}")
return False
def main():
"""Main deployment function"""
print("π Textilindo AI Assistant - Push to Hugging Face Spaces")
print("=" * 60)
# Check if we're in the right directory
if not Path("scripts").exists():
print("β Scripts directory not found. Please run from the project root.")
sys.exit(1)
# Step 1: Check git status
if not check_git_status():
sys.exit(1)
# Step 2: Setup Git LFS
if not setup_git_lfs():
sys.exit(1)
# Step 3: Create .gitignore
create_gitignore()
# Step 4: Prepare Dockerfile
if not prepare_dockerfile():
sys.exit(1)
# Step 5: Create space configuration
create_space_config()
# Step 6: Commit and push
if commit_and_push():
print("\nπ Successfully pushed to Hugging Face Spaces!")
print("\nπ Next steps:")
print("1. Go to your Hugging Face Space")
print("2. Check the build logs")
print("3. Set environment variables if needed")
print("4. Test the application")
else:
print("\nβ Failed to push. Please check the errors above.")
print("\nπ‘ Manual steps:")
print("1. Add remote: git remote add origin <your-hf-space-url>")
print("2. Push: git push origin main")
if __name__ == "__main__":
main()
|