Sousaneitor30000 commited on
Commit
e1983e2
·
verified ·
1 Parent(s): 686674e

Create start.py

Browse files
Files changed (1) hide show
  1. start.py +184 -0
start.py ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ 🛡️ AntiScam AI Pro - Script de Inicio
4
+ Verifica configuración y lanza la aplicación
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import subprocess
10
+ from pathlib import Path
11
+
12
+ def check_python_version():
13
+ """Verifica versión de Python"""
14
+ if sys.version_info < (3, 8):
15
+ print("❌ Python 3.8+ requerido")
16
+ print(f" Tu versión: {sys.version}")
17
+ return False
18
+ print(f"✅ Python {sys.version_info.major}.{sys.version_info.minor}")
19
+ return True
20
+
21
+ def check_requirements():
22
+ """Verifica si están instaladas las dependencias"""
23
+ try:
24
+ import gradio
25
+ import stripe
26
+ import transformers
27
+ print("✅ Dependencias principales instaladas")
28
+ return True
29
+ except ImportError as e:
30
+ print(f"❌ Dependencia faltante: {e}")
31
+ print("💡 Ejecuta: pip install -r requirements.txt")
32
+ return False
33
+
34
+ def check_env_file():
35
+ """Verifica archivo .env"""
36
+ env_path = Path(".env")
37
+ if not env_path.exists():
38
+ print("⚠️ Archivo .env no encontrado")
39
+ print("💡 Copia .env.example como .env y configura tus credenciales")
40
+ return False
41
+
42
+ # Verificar variables críticas
43
+ from dotenv import load_dotenv
44
+ load_dotenv()
45
+
46
+ missing_vars = []
47
+ optional_vars = []
48
+
49
+ # Variables críticas
50
+ if not os.getenv("STRIPE_SECRET_KEY"):
51
+ missing_vars.append("STRIPE_SECRET_KEY")
52
+ if not os.getenv("EMAIL_USER"):
53
+ optional_vars.append("EMAIL_USER")
54
+
55
+ if missing_vars:
56
+ print(f"❌ Variables de entorno faltantes: {', '.join(missing_vars)}")
57
+ return False
58
+
59
+ if optional_vars:
60
+ print(f"⚠️ Variables opcionales no configuradas: {', '.join(optional_vars)}")
61
+ print(" La aplicación funcionará en modo simulado")
62
+
63
+ print("✅ Archivo .env configurado")
64
+ return True
65
+
66
+ def check_database():
67
+ """Verifica/crea base de datos"""
68
+ try:
69
+ import sqlite3
70
+ conn = sqlite3.connect("antiscam_pro.db")
71
+ conn.close()
72
+ print("✅ Base de datos accesible")
73
+ return True
74
+ except Exception as e:
75
+ print(f"❌ Error con base de datos: {e}")
76
+ return False
77
+
78
+ def install_requirements():
79
+ """Instala dependencias automáticamente"""
80
+ print("📦 Instalando dependencias...")
81
+ try:
82
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
83
+ print("✅ Dependencias instaladas")
84
+ return True
85
+ except subprocess.CalledProcessError:
86
+ print("❌ Error instalando dependencias")
87
+ return False
88
+
89
+ def create_env_template():
90
+ """Crea archivo .env desde template"""
91
+ if not Path(".env.example").exists():
92
+ print("❌ Archivo .env.example no encontrado")
93
+ return False
94
+
95
+ try:
96
+ import shutil
97
+ shutil.copy(".env.example", ".env")
98
+ print("✅ Archivo .env creado desde template")
99
+ print("⚠️ IMPORTANTE: Edita .env con tus credenciales reales")
100
+ return True
101
+ except Exception as e:
102
+ print(f"❌ Error creando .env: {e}")
103
+ return False
104
+
105
+ def main():
106
+ """Función principal de verificación y inicio"""
107
+ print("🛡️ ANTISCAM AI PRO - VERIFICACIÓN DE SISTEMA")
108
+ print("=" * 50)
109
+
110
+ # Verificaciones paso a paso
111
+ checks = [
112
+ ("Versión de Python", check_python_version),
113
+ ("Base de datos", check_database),
114
+ ]
115
+
116
+ # Verificar dependencias
117
+ if not check_requirements():
118
+ response = input("¿Instalar dependencias automáticamente? (y/N): ")
119
+ if response.lower() == 'y':
120
+ if not install_requirements():
121
+ sys.exit(1)
122
+ else:
123
+ print("❌ Dependencias requeridas no instaladas")
124
+ sys.exit(1)
125
+
126
+ # Verificar .env
127
+ if not check_env_file():
128
+ if not Path(".env").exists():
129
+ response = input("¿Crear archivo .env desde template? (y/N): ")
130
+ if response.lower() == 'y':
131
+ if create_env_template():
132
+ print("\n📝 SIGUIENTE PASO:")
133
+ print(" 1. Edita el archivo .env con tus credenciales")
134
+ print(" 2. Ejecuta este script nuevamente")
135
+ sys.exit(0)
136
+
137
+ print("\n🔧 CONFIGURACIÓN REQUERIDA:")
138
+ print(" 1. Copia .env.example como .env")
139
+ print(" 2. Configura tus credenciales de Stripe y Gmail")
140
+ print(" 3. Ejecuta este script nuevamente")
141
+ sys.exit(1)
142
+
143
+ # Ejecutar verificaciones
144
+ all_passed = True
145
+ for name, check_func in checks:
146
+ try:
147
+ if not check_func():
148
+ all_passed = False
149
+ except Exception as e:
150
+ print(f"❌ Error en {name}: {e}")
151
+ all_passed = False
152
+
153
+ print("\n" + "=" * 50)
154
+
155
+ if all_passed:
156
+ print("🚀 SISTEMA LISTO - INICIANDO ANTISCAM AI PRO...")
157
+ print("=" * 50)
158
+
159
+ # Importar y ejecutar la aplicación
160
+ try:
161
+ from app import create_interface
162
+ app = create_interface()
163
+ app.launch(
164
+ server_name="0.0.0.0",
165
+ server_port=7860,
166
+ share=True,
167
+ show_error=True
168
+ )
169
+ except Exception as e:
170
+ print(f"❌ Error iniciando aplicación: {e}")
171
+ sys.exit(1)
172
+ else:
173
+ print("❌ VERIFICACIONES FALLIDAS")
174
+ print(" Resuelve los errores arriba y ejecuta nuevamente")
175
+ sys.exit(1)
176
+
177
+ if __name__ == "__main__":
178
+ try:
179
+ main()
180
+ except KeyboardInterrupt:
181
+ print("\n👋 Aplicación detenida por el usuario")
182
+ except Exception as e:
183
+ print(f"\n💥 Error crítico: {e}")
184
+ sys.exit(1)