Spaces:
Paused
Paused
Download start_services.py from VAH6002/ai_data_scientist: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/start_services.py
- Command line
-
hf download hf://spaces/VAH6002/ai_data_scientist/start_services.py
-
curl -L -o start_services.py https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/start_services.py
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() |