File size: 2,157 Bytes
0f6d44d
 
 
216bd52
 
 
 
 
 
 
 
 
 
 
 
 
0f6d44d
 
 
 
216bd52
0f6d44d
 
 
 
216bd52
 
 
 
 
 
0f6d44d
 
216bd52
 
 
 
 
 
 
a0ced08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216bd52
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
EcoMCP UI Entry Point - Launch Gradio interface

Starts the web-based UI for EcoMCP at http://localhost:7860

The MCP server should be running separately via run_server.py
or the UI will show reduced functionality.

Environment Variables:
    GRADIO_SERVER_NAME: Server host (default: 0.0.0.0)
    GRADIO_SERVER_PORT: Server port (default: 7860)
    
Example:
    python3 run_ui.py
    # Open http://localhost:7860 in your browser
"""

import sys
import os
import logging

# Add project root to path
sys.path.insert(0, os.path.dirname(__file__))

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

if __name__ == "__main__":
    try:
        logger.info("Loading EcoMCP UI...")
        from src.ui.app import create_app
        
        logger.info("Creating Gradio app...")
        app = create_app()
        
        # Check if running in Hugging Face Space environment
        import os
        is_hf_space = os.environ.get("HUGGINGFACE_SPACES") == "1"

        if is_hf_space:
            logger.info("Launching EcoMCP in Hugging Face Space environment")
            app.launch(
                server_name="0.0.0.0",
                server_port=7860,
                show_error=True,
                share=False,
                show_tips=True
            )
        else:
            logger.info("Launching EcoMCP at http://localhost:7860")
            app.launch(
                server_name="0.0.0.0",
                server_port=7860,
                show_error=True,
                share=False
            )
    except ImportError as e:
        logger.error(f"Failed to import required module: {e}")
        logger.error("Make sure all dependencies are installed: pip install -r requirements.txt")
        sys.exit(1)
    except KeyboardInterrupt:
        logger.info("UI shutdown requested")
        sys.exit(0)
    except Exception as e:
        logger.error(f"Failed to start UI: {e}")
        logger.error("Check that all dependencies are installed and configured correctly")
        sys.exit(1)