ai_data_scientist / start_services.py
VAH6002's picture
Upload 4 files
b989cf0 verified
Raw History Blame Contribute Delete
2.32 kB
"""
Combined service startup for Hugging Face Spaces
Starts both the orchestrator and Streamlit app
"""
import os
import sys
import subprocess
import threading
import time
import signal
from pathlib import Path
def start_orchestrator():
"""Start the FastAPI orchestrator service."""
try:
print("πŸš€ Starting orchestrator service...")
# Set environment variables
os.environ.setdefault('FASTAPI_HOST', '0.0.0.0')
os.environ.setdefault('FASTAPI_PORT', '8000')
# Start the orchestrator
subprocess.run([
sys.executable, "-m", "uvicorn",
"orchestrator.main:app",
"--host", "0.0.0.0",
"--port", "8000",
"--reload"
], check=True)
except Exception as e:
print(f"❌ Failed to start orchestrator: {e}")
return False
return True
def start_streamlit():
"""Start the Streamlit application."""
try:
print("🎨 Starting Streamlit app...")
# Wait a moment for orchestrator to start
time.sleep(5)
# Start Streamlit
subprocess.run([
sys.executable, "-m", "streamlit", "run", "app.py",
"--server.port", "7860",
"--server.address", "0.0.0.0",
"--server.headless", "true"
], check=True)
except Exception as e:
print(f"❌ Failed to start Streamlit: {e}")
return False
return True
def main():
"""Main startup function."""
print("πŸ€– MCP AI Data Scientist - Starting Services")
# Check if we're in Hugging Face Spaces
if os.getenv('SPACE_ID'):
print("🌟 Running in Hugging Face Spaces")
try:
# Start orchestrator in background thread
orchestrator_thread = threading.Thread(target=start_orchestrator, daemon=True)
orchestrator_thread.start()
# Start Streamlit in main thread
start_streamlit()
except KeyboardInterrupt:
print("\nπŸ›‘ Shutting down services...")
sys.exit(0)
except Exception as e:
print(f"❌ Startup error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()