ecomcp / run_ui.py
vinhnx90's picture
Update commit
a0ced08
#!/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)