| | |
| | """ |
| | Script para subir archivos al Space de Hugging Face |
| | """ |
| |
|
| | import os |
| | import subprocess |
| | import sys |
| | from pathlib import Path |
| |
|
| | def run_command(command, cwd=None): |
| | """Ejecuta un comando y retorna el resultado""" |
| | try: |
| | result = subprocess.run(command, shell=True, capture_output=True, text=True, cwd=cwd) |
| | return result.returncode == 0, result.stdout, result.stderr |
| | except Exception as e: |
| | return False, "", str(e) |
| |
|
| | def check_git_status(): |
| | """Verifica el estado de Git""" |
| | print("🔍 Verificando estado de Git...") |
| | |
| | |
| | success, stdout, stderr = run_command("git status") |
| | if not success: |
| | print("❌ No es un repositorio Git. Inicializando...") |
| | run_command("git init") |
| | run_command("git add .") |
| | run_command('git commit -m "Initial commit"') |
| | return True |
| | |
| | print("✅ Repositorio Git encontrado") |
| | return True |
| |
|
| | def add_remote(): |
| | """Añade el remote del Space de Hugging Face""" |
| | print("🔗 Configurando remote de Hugging Face...") |
| | |
| | space_url = "https://huggingface.co/spaces/Ntdeseb/test3" |
| | |
| | |
| | success, stdout, stderr = run_command("git remote -v") |
| | if "huggingface" in stdout or "test3" in stdout: |
| | print("✅ Remote ya configurado") |
| | return True |
| | |
| | |
| | success, stdout, stderr = run_command(f"git remote add huggingface {space_url}") |
| | if success: |
| | print("✅ Remote añadido correctamente") |
| | return True |
| | else: |
| | print(f"❌ Error añadiendo remote: {stderr}") |
| | return False |
| |
|
| | def commit_and_push(): |
| | """Hace commit y push de los cambios""" |
| | print("📤 Subiendo cambios al Space...") |
| | |
| | |
| | success, stdout, stderr = run_command("git add .") |
| | if not success: |
| | print(f"❌ Error añadiendo archivos: {stderr}") |
| | return False |
| | |
| | |
| | success, stdout, stderr = run_command('git commit -m "Update VEO3 Free Space configuration"') |
| | if not success: |
| | print(f"❌ Error haciendo commit: {stderr}") |
| | return False |
| | |
| | |
| | success, stdout, stderr = run_command("git push huggingface main") |
| | if success: |
| | print("✅ Cambios subidos correctamente al Space") |
| | return True |
| | else: |
| | print(f"❌ Error subiendo cambios: {stderr}") |
| | return False |
| |
|
| | def verify_files(): |
| | """Verifica que todos los archivos necesarios estén presentes""" |
| | print("🔍 Verificando archivos necesarios...") |
| | |
| | required_files = [ |
| | "README.md", |
| | "app.py", |
| | "requirements.txt", |
| | "setup.py", |
| | "space_config.py", |
| | ".gitignore", |
| | ".gitattributes" |
| | ] |
| | |
| | missing_files = [] |
| | for file in required_files: |
| | if not os.path.exists(file): |
| | missing_files.append(file) |
| | |
| | if missing_files: |
| | print(f"❌ Archivos faltantes: {', '.join(missing_files)}") |
| | return False |
| | |
| | print("✅ Todos los archivos necesarios están presentes") |
| | return True |
| |
|
| | def main(): |
| | """Función principal""" |
| | print("🚀 Iniciando subida al Space de Hugging Face...") |
| | print("=" * 60) |
| | |
| | |
| | if not verify_files(): |
| | print("❌ Faltan archivos necesarios") |
| | return False |
| | |
| | |
| | if not check_git_status(): |
| | print("❌ Error con Git") |
| | return False |
| | |
| | |
| | if not add_remote(): |
| | print("❌ Error configurando remote") |
| | return False |
| | |
| | |
| | if not commit_and_push(): |
| | print("❌ Error subiendo cambios") |
| | return False |
| | |
| | print("\n🎉 ¡Subida completada exitosamente!") |
| | print("🌐 Tu Space estará disponible en: https://huggingface.co/spaces/Ntdeseb/test3") |
| | print("\n📝 Notas importantes:") |
| | print("- El Space puede tardar 5-10 minutos en iniciar") |
| | print("- Los modelos se descargarán automáticamente") |
| | print("- Verifica los logs en la interfaz de Hugging Face") |
| | |
| | return True |
| |
|
| | if __name__ == "__main__": |
| | success = main() |
| | sys.exit(0 if success else 1) |