File size: 2,875 Bytes
d520909
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
SPARKNET Demo Launcher

Cross-platform launcher for the Streamlit demo.

Usage:
    python run_demo.py [--port PORT]
"""

import subprocess
import sys
import os
from pathlib import Path

def check_dependencies():
    """Check and install required dependencies."""
    print("πŸ“¦ Checking dependencies...")

    try:
        import streamlit
        print(f"   βœ… Streamlit {streamlit.__version__}")
    except ImportError:
        print("   πŸ“₯ Installing Streamlit...")
        subprocess.run([sys.executable, "-m", "pip", "install", "streamlit"], check=True)

    try:
        import pandas
        print(f"   βœ… Pandas {pandas.__version__}")
    except ImportError:
        print("   πŸ“₯ Installing Pandas...")
        subprocess.run([sys.executable, "-m", "pip", "install", "pandas"], check=True)

    try:
        import httpx
        print(f"   βœ… httpx {httpx.__version__}")
    except ImportError:
        print("   πŸ“₯ Installing httpx...")
        subprocess.run([sys.executable, "-m", "pip", "install", "httpx"], check=True)


def check_ollama():
    """Check if Ollama is running."""
    print("\nπŸ” Checking Ollama status...")

    try:
        import httpx
        with httpx.Client(timeout=2.0) as client:
            response = client.get("http://localhost:11434/api/tags")
            if response.status_code == 200:
                data = response.json()
                models = len(data.get("models", []))
                print(f"   βœ… Ollama is running ({models} models)")
                return True
    except Exception:
        pass

    print("   ⚠️  Ollama not running (demo will use simulated responses)")
    print("       Start with: ollama serve")
    return False


def main():
    """Main entry point."""
    import argparse

    parser = argparse.ArgumentParser(description="SPARKNET Demo Launcher")
    parser.add_argument("--port", type=int, default=8501, help="Port to run on")
    args = parser.parse_args()

    print("=" * 50)
    print("πŸ”₯ SPARKNET Demo Launcher")
    print("=" * 50)
    print()

    # Get project root
    project_root = Path(__file__).parent
    demo_app = project_root / "demo" / "app.py"

    if not demo_app.exists():
        print(f"❌ Demo app not found: {demo_app}")
        sys.exit(1)

    # Check dependencies
    check_dependencies()

    # Check Ollama
    check_ollama()

    # Launch
    print()
    print(f"πŸš€ Launching SPARKNET Demo on port {args.port}...")
    print(f"   URL: http://localhost:{args.port}")
    print()
    print("Press Ctrl+C to stop")
    print("=" * 50)
    print()

    # Run Streamlit
    os.chdir(project_root)
    subprocess.run([
        sys.executable, "-m", "streamlit", "run",
        str(demo_app),
        "--server.port", str(args.port),
        "--server.headless", "true",
    ])


if __name__ == "__main__":
    main()