Spaces:
Paused
Paused
File size: 5,786 Bytes
922c3ba |
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 |
#!/usr/bin/env python3
"""
Final Deployment Execution Script
================================
This script guides you through the complete deployment process to Hugging Face Spaces.
Based on: https://dev.to/koolkamalkishor/how-to-upload-your-project-to-hugging-face-spaces-a-beginners-step-by-step-guide-1pkn
"""
import os
import sys
import subprocess
import time
def print_header():
"""Print deployment header"""
print("π Legal Dashboard OCR - Final Deployment")
print("=" * 60)
print("β
All validation checks passed!")
print("β
Encoding issues fixed!")
print("β
Project ready for deployment!")
print("=" * 60)
def get_deployment_info():
"""Get deployment information from user"""
print("\nπ Deployment Information")
print("-" * 30)
username = input("Enter your Hugging Face username: ").strip()
space_name = input(
"Enter Space name (e.g., legal-dashboard-ocr): ").strip()
hf_token = input("Enter your Hugging Face token: ").strip()
if not all([username, space_name, hf_token]):
print("β All fields are required!")
return None
return {
'username': username,
'space_name': space_name,
'hf_token': hf_token,
'space_url': f"https://huggingface.co/spaces/{username}/{space_name}"
}
def create_space_instructions(info):
"""Provide instructions for creating the Space"""
print(f"\nπ Step 1: Create Hugging Face Space")
print("-" * 40)
print("1. Go to: https://huggingface.co/spaces")
print("2. Click 'Create new Space'")
print("3. Configure:")
print(f" - Owner: {info['username']}")
print(f" - Space name: {info['space_name']}")
print(" - SDK: Gradio")
print(" - License: MIT")
print(" - Visibility: Public")
print(" - Hardware: CPU (Free tier)")
print("4. Click 'Create Space'")
print(f"5. Your Space URL will be: {info['space_url']}")
input("\nPress Enter when you've created the Space...")
def prepare_git_repository(info):
"""Prepare Git repository for deployment"""
print(f"\nπ Step 2: Prepare Git Repository")
print("-" * 40)
# Change to huggingface_space directory
os.chdir("huggingface_space")
try:
# Initialize git repository
print("Initializing Git repository...")
subprocess.run(["git", "init"], check=True)
# Add remote origin
remote_url = f"https://{info['username']}:{info['hf_token']}@huggingface.co/spaces/{info['username']}/{info['space_name']}"
print("Adding remote origin...")
subprocess.run(
["git", "remote", "add", "origin", remote_url], check=True)
print("β
Git repository prepared successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"β Git setup failed: {e}")
return False
def deploy_files():
"""Deploy files to Hugging Face Space"""
print(f"\nπ Step 3: Deploy Files")
print("-" * 40)
try:
# Add all files
print("Adding files to Git...")
subprocess.run(["git", "add", "."], check=True)
# Commit changes
print("Committing changes...")
subprocess.run(
["git", "commit", "-m", "Initial deployment of Legal Dashboard OCR"], check=True)
# Push to main branch
print("Pushing to Hugging Face...")
subprocess.run(["git", "push", "-u", "origin", "main"], check=True)
print("β
Files deployed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"β Deployment failed: {e}")
return False
def configure_environment(info):
"""Provide instructions for environment configuration"""
print(f"\nπ Step 4: Configure Environment Variables")
print("-" * 40)
print("1. Go to your Space page:")
print(f" {info['space_url']}")
print("2. Click 'Settings' tab")
print("3. Add environment variable:")
print(" - Name: HF_TOKEN")
print(" - Value: Your Hugging Face access token")
print("4. Click 'Save'")
print("5. Wait for the Space to rebuild")
input("\nPress Enter when you've configured the environment...")
def verify_deployment(info):
"""Verify the deployment"""
print(f"\nπ Step 5: Verify Deployment")
print("-" * 40)
print("1. Visit your Space:")
print(f" {info['space_url']}")
print("2. Check that the Space loads without errors")
print("3. Test file upload functionality")
print("4. Upload a Persian PDF document")
print("5. Verify OCR processing works")
print("6. Test AI analysis features")
print("7. Check dashboard functionality")
print(f"\nπ Deployment Complete!")
print(f"π Your Space is live at: {info['space_url']}")
def main():
"""Main deployment function"""
print_header()
# Get deployment information
info = get_deployment_info()
if not info:
return 1
# Step 1: Create Space
create_space_instructions(info)
# Step 2: Prepare Git repository
if not prepare_git_repository(info):
return 1
# Step 3: Deploy files
if not deploy_files():
return 1
# Step 4: Configure environment
configure_environment(info)
# Step 5: Verify deployment
verify_deployment(info)
print(f"\nπ Congratulations! Your Legal Dashboard OCR is now live!")
print(f"π Documentation: {info['space_url']}")
print(f"π§ For updates, use: git push origin main")
return 0
if __name__ == "__main__":
sys.exit(main())
|