CoolFace
Apppublic

akv2011/Linkedin_reach

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
start_server.py94 linesDownload Raw Back to synapse-agent
1#!/usr/bin/env python32"""3Enhanced startup script for the Synapse AI LinkedIn Sourcing Agent4This script handles environment setup and starts the FastAPI server5"""6 7import os8import sys9import subprocess10from pathlib import Path11 12def setup_environment():13    """Set up the environment for the application"""14    # Get the current directory (synapse-agent)15    current_dir = Path(__file__).parent16    17    # Add the current directory to Python path so imports work18    if str(current_dir) not in sys.path:19        sys.path.insert(0, str(current_dir))20    21    # Add the src directory to Python path22    src_dir = current_dir / "src"23    if str(src_dir) not in sys.path:24        sys.path.insert(0, str(src_dir))25    26    # Load environment variables27    from dotenv import load_dotenv28    env_file = current_dir / ".env"29    if env_file.exists():30        load_dotenv(env_file)31        print(f"[+] Loaded environment from: {env_file}")32        33        # Verify critical variables34        required_vars = ["GEMINI_API_KEY", "GOOGLE_API_KEY", "CUSTOM_SEARCH_ENGINE_ID", "LINKEDIN_SESSION_COOKIE"]35        missing_vars = []36        for var in required_vars:37            if not os.getenv(var):38                missing_vars.append(var)39        40        if missing_vars:41            print(f"[!] Missing environment variables: {', '.join(missing_vars)}")42        else:43            print("[+] All required environment variables are set")44    else:45        print(f"[-] Environment file not found: {env_file}")46        return False47    48    return True49 50def start_server():51    """Start the FastAPI server"""52    print("Synapse AI LinkedIn Sourcing Agent")53    print("==================================================")54    55    if not setup_environment():56        print("[-] Environment setup failed")57        return58    59    try:60        # Set the PYTHONPATH environment variable61        current_dir = Path(__file__).parent62        env = os.environ.copy()63        env['PYTHONPATH'] = str(current_dir)64        65        print("Starting server...")66        print("Server will be available at: http://localhost:8000")67        print("Web interface: http://localhost:8000/web")68        print("API docs: http://localhost:8000/docs")69        print("\nPress Ctrl+C to stop the server")70        print("--------------------------------------------------")71        72        # Run uvicorn command73        cmd = [74            sys.executable, "-m", "uvicorn", 75            "api:app", 76            "--host", "0.0.0.0", 77            "--port", "8000", 78            "--reload"79        ]80        81        subprocess.run(cmd, cwd=current_dir, env=env)82        83    except KeyboardInterrupt:84        print("\nServer stopped by user")85    except Exception as e:86        print(f"Error starting server: {e}")87        print("\nTroubleshooting:")88        print("1. Make sure you're in the synapse-agent directory")89        print("2. Check that all dependencies are installed: pip install -r requirements.txt")90        print("3. Verify your .env file has all required variables")91 92if __name__ == "__main__":93    start_server()94