File size: 2,361 Bytes
80e1d6c |
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 |
#!/usr/bin/env python3
"""
start.py
SCRIPT MAESTRO DE LANZAMIENTO
Ejecuta: python start.py
"""
import subprocess
import sys
import time
import signal
import os
import webbrowser
# Lista para guardar los procesos y poder cerrarlos luego
processes = []
def run_process(command, name):
"""Lanza un proceso en segundo plano"""
print(f"🚀 Iniciando {name}...")
# Usamos sys.executable para asegurar que usa el mismo Python del entorno virtual
try:
# shell=True en Windows a veces ayuda con los paths, pero subprocess directo es más seguro
# Dividimos el comando en una lista para subprocess
cmd_list = command.split()
p = subprocess.Popen(cmd_list, cwd=os.getcwd())
processes.append(p)
return p
except Exception as e:
print(f"❌ Error al iniciar {name}: {e}")
return None
def cleanup(signum, frame):
"""Cierra todo al pulsar Ctrl+C"""
print("\n🛑 Cerrando todos los servidores...")
for p in processes:
try:
p.terminate()
except:
pass
sys.exit(0)
# Capturar Ctrl+C
signal.signal(signal.SIGINT, cleanup)
def main():
print("\n🛡️ CONTRACT GUARDIAN - PREPARANDO DEMO 🛡️")
print("============================================")
# 1. INICIAR SERVIDORES MCP
# Ajusta estas rutas si cambiaste nombres, pero según tu foto son estas:
# Servidor de Leyes (Puerto 8001)
run_process(f"{sys.executable} mcp_servers/law_retriever/laws_retriever_server.py", "Law Retriever (Port 8001)")
# Servidor de Clasificación (Puerto 8002)
run_process(f"{sys.executable} mcp_servers/clause_classifier/clause_classifier_server.py", "Clause Classifier (Port 8002)")
print("⏳ Esperando 5 segundos a que los servidores arranquen...")
time.sleep(5)
# 2. INICIAR INTERFAZ DE USUARIO
print("🎨 Iniciando Interfaz Gradio...")
ui_process = run_process(f"{sys.executable} ui/app.py", "User Interface")
# 3. ABRIR NAVEGADOR
print("🌍 Abriendo navegador...")
time.sleep(2)
webbrowser.open("http://localhost:7860")
print("\n✅ TODO LISTO. Presiona Ctrl+C para detener todo.\n")
# Mantener el script vivo mientras la UI funcione
if ui_process:
ui_process.wait()
cleanup(None, None)
if __name__ == "__main__":
main()
|