Spaces:
Running
Running
File size: 5,769 Bytes
e1983e2 |
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 172 173 174 175 176 177 178 179 180 181 182 183 184 |
#!/usr/bin/env python3
"""
🛡️ AntiScam AI Pro - Script de Inicio
Verifica configuración y lanza la aplicación
"""
import os
import sys
import subprocess
from pathlib import Path
def check_python_version():
"""Verifica versión de Python"""
if sys.version_info < (3, 8):
print("❌ Python 3.8+ requerido")
print(f" Tu versión: {sys.version}")
return False
print(f"✅ Python {sys.version_info.major}.{sys.version_info.minor}")
return True
def check_requirements():
"""Verifica si están instaladas las dependencias"""
try:
import gradio
import stripe
import transformers
print("✅ Dependencias principales instaladas")
return True
except ImportError as e:
print(f"❌ Dependencia faltante: {e}")
print("💡 Ejecuta: pip install -r requirements.txt")
return False
def check_env_file():
"""Verifica archivo .env"""
env_path = Path(".env")
if not env_path.exists():
print("⚠️ Archivo .env no encontrado")
print("💡 Copia .env.example como .env y configura tus credenciales")
return False
# Verificar variables críticas
from dotenv import load_dotenv
load_dotenv()
missing_vars = []
optional_vars = []
# Variables críticas
if not os.getenv("STRIPE_SECRET_KEY"):
missing_vars.append("STRIPE_SECRET_KEY")
if not os.getenv("EMAIL_USER"):
optional_vars.append("EMAIL_USER")
if missing_vars:
print(f"❌ Variables de entorno faltantes: {', '.join(missing_vars)}")
return False
if optional_vars:
print(f"⚠️ Variables opcionales no configuradas: {', '.join(optional_vars)}")
print(" La aplicación funcionará en modo simulado")
print("✅ Archivo .env configurado")
return True
def check_database():
"""Verifica/crea base de datos"""
try:
import sqlite3
conn = sqlite3.connect("antiscam_pro.db")
conn.close()
print("✅ Base de datos accesible")
return True
except Exception as e:
print(f"❌ Error con base de datos: {e}")
return False
def install_requirements():
"""Instala dependencias automáticamente"""
print("📦 Instalando dependencias...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("✅ Dependencias instaladas")
return True
except subprocess.CalledProcessError:
print("❌ Error instalando dependencias")
return False
def create_env_template():
"""Crea archivo .env desde template"""
if not Path(".env.example").exists():
print("❌ Archivo .env.example no encontrado")
return False
try:
import shutil
shutil.copy(".env.example", ".env")
print("✅ Archivo .env creado desde template")
print("⚠️ IMPORTANTE: Edita .env con tus credenciales reales")
return True
except Exception as e:
print(f"❌ Error creando .env: {e}")
return False
def main():
"""Función principal de verificación y inicio"""
print("🛡️ ANTISCAM AI PRO - VERIFICACIÓN DE SISTEMA")
print("=" * 50)
# Verificaciones paso a paso
checks = [
("Versión de Python", check_python_version),
("Base de datos", check_database),
]
# Verificar dependencias
if not check_requirements():
response = input("¿Instalar dependencias automáticamente? (y/N): ")
if response.lower() == 'y':
if not install_requirements():
sys.exit(1)
else:
print("❌ Dependencias requeridas no instaladas")
sys.exit(1)
# Verificar .env
if not check_env_file():
if not Path(".env").exists():
response = input("¿Crear archivo .env desde template? (y/N): ")
if response.lower() == 'y':
if create_env_template():
print("\n📝 SIGUIENTE PASO:")
print(" 1. Edita el archivo .env con tus credenciales")
print(" 2. Ejecuta este script nuevamente")
sys.exit(0)
print("\n🔧 CONFIGURACIÓN REQUERIDA:")
print(" 1. Copia .env.example como .env")
print(" 2. Configura tus credenciales de Stripe y Gmail")
print(" 3. Ejecuta este script nuevamente")
sys.exit(1)
# Ejecutar verificaciones
all_passed = True
for name, check_func in checks:
try:
if not check_func():
all_passed = False
except Exception as e:
print(f"❌ Error en {name}: {e}")
all_passed = False
print("\n" + "=" * 50)
if all_passed:
print("🚀 SISTEMA LISTO - INICIANDO ANTISCAM AI PRO...")
print("=" * 50)
# Importar y ejecutar la aplicación
try:
from app import create_interface
app = create_interface()
app.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
show_error=True
)
except Exception as e:
print(f"❌ Error iniciando aplicación: {e}")
sys.exit(1)
else:
print("❌ VERIFICACIONES FALLIDAS")
print(" Resuelve los errores arriba y ejecuta nuevamente")
sys.exit(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n👋 Aplicación detenida por el usuario")
except Exception as e:
print(f"\n💥 Error crítico: {e}")
sys.exit(1) |