Spaces:
Build error
Build error
| """ | |
| 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() |