""" Quick diagnostic to check if API keys are accessible """ import os from dotenv import load_dotenv # Load .env file load_dotenv() print("=" * 80) print("API KEY DIAGNOSTIC CHECK") print("=" * 80) print() # Check SERPER_API_KEY serper_key = os.getenv('SERPER_API_KEY') print(f"SERPER_API_KEY: {'✓ FOUND' if serper_key else '✗ NOT FOUND'}") if serper_key: print(f" Value: {serper_key[:10]}..." if len(serper_key) > 10 else f" Value: {serper_key}") print(f" Length: {len(serper_key)} characters") else: print(" ⚠ This key is REQUIRED for real contact discovery!") print(" Get it from: https://serper.dev") print() # Check HF_API_TOKEN hf_token = os.getenv('HF_API_TOKEN') print(f"HF_API_TOKEN: {'✓ FOUND' if hf_token else '✗ NOT FOUND'}") if hf_token: print(f" Value: {hf_token[:10]}..." if len(hf_token) > 10 else f" Value: {hf_token}") print(f" Length: {len(hf_token)} characters") else: print(" ⚠ This key is needed for AI email generation") print() # Check if running in HF Space space_id = os.getenv('SPACE_ID') space_author = os.getenv('SPACE_AUTHOR_NAME') if space_id or space_author: print(f"🚀 Running in HuggingFace Space") print(f" Space ID: {space_id}") print(f" Author: {space_author}") print() print("NOTE: In HF Spaces, secrets should be set in:") print(" Settings → Repository secrets") print(" Then restart the Space for changes to take effect") else: print("💻 Running locally") print() print("For local development, create a .env file with:") print(" SERPER_API_KEY=your-key-here") print(" HF_API_TOKEN=your-token-here") print() print("=" * 80) # Test web search service print("\nTesting WebSearchService initialization...") try: from services.web_search import get_search_service search = get_search_service() if search.api_key: print("✓ WebSearchService initialized with API key") else: print("✗ WebSearchService initialized WITHOUT API key") print(" Web search will fail!") except Exception as e: print(f"✗ Error initializing WebSearchService: {e}") print() print("=" * 80)