Spaces:
Build error
Build error
File size: 5,322 Bytes
d6b06b4 | 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 | """
Utility script to help deploy the PromptMaster app to Hugging Face Spaces
"""
import os
import shutil
import subprocess
import sys
def check_requirements():
"""Check if the required packages are installed"""
try:
import gradio
import pandas
import numpy
print("✅ Required packages are installed")
return True
except ImportError as e:
print(f"❌ Missing package: {e}")
print("Please run: pip install -r requirements.txt")
return False
def check_git():
"""Check if git is installed"""
try:
subprocess.run(["git", "--version"], check=True, stdout=subprocess.PIPE)
print("✅ Git is installed")
return True
except (subprocess.SubprocessError, FileNotFoundError):
print("❌ Git is not installed. Please install Git: https://git-scm.com/downloads")
return False
def check_huggingface_cli():
"""Check if the Hugging Face CLI is installed"""
try:
subprocess.run(["huggingface-cli", "--version"], check=True, stdout=subprocess.PIPE)
print("✅ Hugging Face CLI is installed")
return True
except (subprocess.SubprocessError, FileNotFoundError):
print("❌ Hugging Face CLI is not installed")
print("Please run: pip install huggingface_hub")
return False
def create_space(space_name):
"""Create a new Hugging Face Space"""
print(f"Creating a new Hugging Face Space: {space_name}")
try:
subprocess.run([
"huggingface-cli", "repo", "create",
space_name,
"--type", "space",
"--space-sdk", "gradio"
], check=True)
print(f"✅ Space '{space_name}' created successfully")
return True
except subprocess.SubprocessError as e:
print(f"❌ Failed to create space: {e}")
return False
def clone_space(space_name, username):
"""Clone the Hugging Face Space"""
repo_url = f"https://huggingface.co/spaces/{username}/{space_name}"
print(f"Cloning space from: {repo_url}")
try:
subprocess.run(["git", "clone", repo_url], check=True)
print(f"✅ Space cloned successfully")
return True
except subprocess.SubprocessError as e:
print(f"❌ Failed to clone space: {e}")
return False
def copy_files(space_name):
"""Copy project files to the Space directory"""
files_to_copy = [
"app.py",
"sample_data.py",
"requirements.txt",
"README.md"
]
print(f"Copying files to {space_name} directory...")
for file in files_to_copy:
if os.path.exists(file):
shutil.copy(file, os.path.join(space_name, file))
print(f" ✅ Copied {file}")
else:
print(f" ⚠️ Warning: {file} not found")
# Generate sample data in the space directory
os.chdir(space_name)
try:
subprocess.run(["python", "sample_data.py"], check=True)
print("✅ Generated sample data")
except subprocess.SubprocessError as e:
print(f"❌ Failed to generate sample data: {e}")
os.chdir("..")
return True
def push_to_huggingface(space_name):
"""Push the code to Hugging Face"""
os.chdir(space_name)
try:
subprocess.run(["git", "add", "."], check=True)
subprocess.run(["git", "commit", "-m", "Initial commit of PromptMaster app"], check=True)
subprocess.run(["git", "push"], check=True)
print("✅ Code pushed to Hugging Face successfully")
os.chdir("..")
return True
except subprocess.SubprocessError as e:
print(f"❌ Failed to push code: {e}")
os.chdir("..")
return False
def main():
print("=" * 50)
print("PromptMaster Deployment to Hugging Face Spaces")
print("=" * 50)
# Check requirements
if not all([
check_requirements(),
check_git(),
check_huggingface_cli()
]):
print("\n❌ Please fix the issues above and run this script again.")
return
# Get username
username = input("\nEnter your Hugging Face username: ").strip()
if not username:
print("❌ Username cannot be empty")
return
# Set space name
space_name = f"{username}/promptmaster-data-analytics"
print(f"\nSpace will be created as: {space_name}")
# Confirm
confirm = input("\nDo you want to continue? (y/n): ").strip().lower()
if confirm != 'y':
print("Deployment cancelled.")
return
# Create space
if not create_space(space_name):
return
# Clone space
if not clone_space(space_name.split("/")[1], username):
return
# Copy files
if not copy_files(space_name.split("/")[1]):
return
# Push to Hugging Face
if not push_to_huggingface(space_name.split("/")[1]):
return
print("\n" + "=" * 50)
print(f"✅ Deployment successful!")
print(f"✅ View your app at: https://huggingface.co/spaces/{space_name}")
print("=" * 50)
if __name__ == "__main__":
main() |