Spaces:
Sleeping
Sleeping
File size: 4,039 Bytes
905e3b7 | 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 | """Deployment script for Hugging Face Spaces."""
import os
import subprocess
import sys
def deploy_to_huggingface():
"""Deploy DocIntel to Hugging Face Spaces."""
print("π Deploying DocIntel to Hugging Face Spaces")
print("="*60)
# Check for HF token
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
print("β HF_TOKEN environment variable not set")
print(" Get your token from: https://huggingface.co/settings/tokens")
sys.exit(1)
# Check for space name
space_name = os.getenv("HF_SPACE_NAME")
if not space_name:
space_name = input("Enter your Hugging Face Space name (e.g., username/docintel): ")
print(f"π¦ Building Docker image...")
# Build Docker image
try:
subprocess.run(
["docker", "build", "-t", "docintel", "."],
check=True,
capture_output=True
)
print("β
Docker image built successfully")
except subprocess.CalledProcessError as e:
print(f"β Docker build failed: {e}")
sys.exit(1)
# Tag for Hugging Face
hf_image = f"registry.hf.space/{space_name}:latest"
print(f"π·οΈ Tagging image: {hf_image}")
try:
subprocess.run(
["docker", "tag", "docintel", hf_image],
check=True
)
print("β
Image tagged successfully")
except subprocess.CalledProcessError as e:
print(f"β Tagging failed: {e}")
sys.exit(1)
# Login to Hugging Face
print("π Logging into Hugging Face...")
try:
subprocess.run(
["docker", "login", "registry.hf.space", "-u", "your-username", "-p", hf_token],
check=True
)
print("β
Login successful")
except subprocess.CalledProcessError as e:
print(f"β Login failed: {e}")
sys.exit(1)
# Push to Hugging Face
print("π€ Pushing to Hugging Face...")
try:
subprocess.run(
["docker", "push", hf_image],
check=True
)
print("β
Push successful")
except subprocess.CalledProcessError as e:
print(f"β Push failed: {e}")
sys.exit(1)
print("\n" + "="*60)
print("β
Deployment complete!")
print(f"π Your space is at: https://huggingface.co/spaces/{space_name}")
print("\nπ Next steps:")
print("1. Add GROQ_API_KEY as a secret in your space settings")
print("2. Wait for the space to build and deploy")
print("3. Start using DocIntel!")
def create_hf_space():
"""Create a new Hugging Face Space."""
print("π Creating Hugging Face Space...")
space_name = input("Enter your desired space name: ")
username = input("Enter your Hugging Face username: ")
# Create space using HF CLI
try:
subprocess.run(
[
"huggingface-cli", "repo", "create",
f"--type", "space",
f"--space_sdk", "docker",
f"{username}/{space_name}"
],
check=True
)
print(f"β
Space created: https://huggingface.co/spaces/{username}/{space_name}")
return f"{username}/{space_name}"
except subprocess.CalledProcessError as e:
print(f"β Space creation failed: {e}")
print("\nPlease create your space manually at:")
print("https://huggingface.co/new-space")
print("Choose: Docker SDK")
return None
if __name__ == "__main__":
print("DocIntel Hugging Face Deployment Tool")
print("1. Deploy to existing Space")
print("2. Create new Space and deploy")
choice = input("Select option (1 or 2): ")
if choice == "1":
deploy_to_huggingface()
elif choice == "2":
space_name = create_hf_space()
if space_name:
# Set env var and deploy
os.environ["HF_SPACE_NAME"] = space_name
deploy_to_huggingface()
else:
print("Invalid choice") |