Spaces:
Running
Running
#!/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) |