File size: 4,246 Bytes
2651fca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
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...")
    
    # Verificar si estamos en un repositorio 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"
    
    # Verificar si el remote ya existe
    success, stdout, stderr = run_command("git remote -v")
    if "huggingface" in stdout or "test3" in stdout:
        print("✅ Remote ya configurado")
        return True
    
    # Añadir remote
    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...")
    
    # Añadir todos los archivos
    success, stdout, stderr = run_command("git add .")
    if not success:
        print(f"❌ Error añadiendo archivos: {stderr}")
        return False
    
    # Hacer commit
    success, stdout, stderr = run_command('git commit -m "Update VEO3 Free Space configuration"')
    if not success:
        print(f"❌ Error haciendo commit: {stderr}")
        return False
    
    # Push al Space
    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)
    
    # Verificar archivos
    if not verify_files():
        print("❌ Faltan archivos necesarios")
        return False
    
    # Verificar estado de Git
    if not check_git_status():
        print("❌ Error con Git")
        return False
    
    # Añadir remote
    if not add_remote():
        print("❌ Error configurando remote")
        return False
    
    # Commit y push
    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)