Spaces:
Build error
Build error
| #!/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() | |