File size: 2,819 Bytes
b4856f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# ModelX Platform - Hackathon Demo Launcher
# This script starts both backend and frontend for the demo

set -e

echo "=========================================="
echo "  🇱🇰 MODELX INTELLIGENCE PLATFORM"
echo "     Hackathon Demo Startup"
echo "=========================================="
echo ""

# Check if .env exists
if [ ! -f .env ]; then
    echo "❌ Error: .env file not found!"
    echo "   Please copy .env.template to .env and add your GROQ_API_KEY"
    exit 1
fi

# Load environment variables
source .env

if [ -z "$GROQ_API_KEY" ]; then
    echo "❌ Error: GROQ_API_KEY not set in .env"
    exit 1
fi

echo "✓ Environment configured"
echo ""

# Install Python dependencies
echo "📦 Installing Python dependencies..."
uv add -r requirements.txt > /dev/null 2>&1
echo "✓ Python dependencies installed"
echo ""

# Activate virtual environment
echo "🔧 Activating virtual environment..."
source .venv/Scripts/activate
echo "✓ Virtual environment activated"
echo ""

# Install Frontend dependencies
echo "📦 Installing Frontend dependencies..."
cd frontend
npm install > /dev/null 2>&1
echo "✓ Frontend dependencies installed"
cd ..
echo ""

# Create ML model output directory (for anomaly detection)
echo "📁 Ensuring ML directories exist..."
mkdir -p models/anomaly-detection/output
echo "✓ ML directories ready"
echo ""

# Start Backend
echo "🚀 Starting Backend API..."
python main.py &
BACKEND_PID=$!

# Wait for backend to start (with retry loop - graphs take time to compile)
echo "⏳ Waiting for backend to initialize (this may take 30-60 seconds)..."
MAX_RETRIES=18
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
    sleep 15
    if curl -s http://localhost:8000/api/status > /dev/null 2>&1; then
        echo "✓ Backend is responding!"
        break
    fi
    RETRY_COUNT=$((RETRY_COUNT + 1))
    echo "   Still waiting... ($((RETRY_COUNT * 15))s elapsed)"
done

# Check if backend is running
if ! curl -s http://localhost:8000/api/status > /dev/null 2>&1; then
    echo "❌ Backend failed to start after 270 seconds!"
    kill $BACKEND_PID 2>/dev/null
    exit 1
fi

echo "✓ Backend running on http://localhost:8000"
echo ""

# Start Frontend
echo "🚀 Starting Frontend..."
cd frontend
npm run dev &
FRONTEND_PID=$!
cd ..

echo ""
echo "=========================================="
echo "  ✅ MODELX PLATFORM IS RUNNING"
echo "=========================================="
echo ""
echo "🌐 Frontend: http://localhost:3000"
echo "🔧 Backend:  http://localhost:8000"
echo "📊 API Docs: http://localhost:8000/docs"
echo ""
echo "Press Ctrl+C to stop all services"
echo ""

# Trap Ctrl+C to stop both processes
trap "echo 'Stopping services...'; kill $BACKEND_PID $FRONTEND_PID 2>/dev/null; exit" INT

# Wait for either process to exit
wait