Spaces:
Sleeping
Sleeping
| """ | |
| Central API configuration and environment setup. | |
| """ | |
| import os | |
| import requests | |
| from typing import Dict, Tuple | |
| class APIConfig: | |
| """Centralized API configuration and validation.""" | |
| def __init__(self): | |
| self.foursquare_api_key = os.environ.get('FOURSQUARE_API_KEY') | |
| self.anthropic_api_key = os.environ.get('ANTHROPIC_API_KEY') | |
| # MCP Server configuration | |
| self.mcp_server_url = "https://srikanthnagelli-mcp-server.hf.space/gradio_api/mcp/sse" | |
| # Set environment if not already set and key is available | |
| if self.foursquare_api_key and not os.environ.get('FOURSQUARE_API_KEY'): | |
| os.environ['FOURSQUARE_API_KEY'] = self.foursquare_api_key | |
| def validate_apis(self) -> Dict[str, bool]: | |
| """Validate API keys and connectivity.""" | |
| results = {} | |
| # Test Foursquare API | |
| if self.foursquare_api_key: | |
| try: | |
| url = "https://api.foursquare.com/v3/places/search" | |
| headers = { | |
| "accept": "application/json", | |
| "Authorization": self.foursquare_api_key | |
| } | |
| params = {"query": "test", "limit": 1} | |
| response = requests.get(url, headers=headers, params=params, timeout=5) | |
| results['foursquare'] = response.status_code == 200 | |
| except Exception: | |
| results['foursquare'] = False | |
| else: | |
| results['foursquare'] = False | |
| # Check Anthropic API key existence | |
| results['anthropic'] = bool(self.anthropic_api_key) | |
| return results | |
| def print_status(self): | |
| """Print API configuration status.""" | |
| print("\n🔧 API Configuration Status:") | |
| validation = self.validate_apis() | |
| if validation['foursquare']: | |
| print("✓ Foursquare API: Connected and working") | |
| else: | |
| print("⚠️ Foursquare API: Connection issues or invalid key") | |
| if validation['anthropic']: | |
| print("✓ Anthropic API Key: Configured") | |
| else: | |
| print("⚠️ Anthropic API Key: Not configured") | |
| print("ℹ️ Set environment variable: ANTHROPIC_API_KEY=your_key") | |
| # Global configuration instance | |
| api_config = APIConfig() | |
| # Location coordinates for major cities | |
| CITY_COORDINATES = { | |
| 'seattle': '47.6062,-122.3321', | |
| 'pike place': '47.6089,-122.3401', | |
| 'downtown seattle': '47.6085,-122.3351', | |
| 'new york': '40.7128,-74.0060', | |
| 'san francisco': '37.7749,-122.4194', | |
| 'los angeles': '34.0522,-118.2437', | |
| 'chicago': '41.8781,-87.6298', | |
| 'boston': '42.3601,-71.0589', | |
| 'portland': '45.5155,-122.6789', | |
| 'denver': '39.7392,-104.9903', | |
| 'miami': '25.7617,-80.1918', | |
| 'las vegas': '36.1699,-115.1398', | |
| 'phoenix': '33.4484,-112.0740', | |
| 'philadelphia': '39.9526,-75.1652', | |
| 'houston': '29.7604,-95.3698', | |
| 'dallas': '32.7767,-96.7970', | |
| 'atlanta': '33.7490,-84.3880', | |
| 'detroit': '42.3314,-83.0458', | |
| 'orlando': '28.5383,-81.3792', | |
| 'san diego': '32.7157,-117.1611', | |
| # Additional California cities | |
| 'folsom': '38.6780,-121.1760', | |
| 'sacramento': '38.5816,-121.4944', | |
| 'san jose': '37.3382,-121.8863', | |
| 'oakland': '37.8044,-122.2711', | |
| 'fresno': '36.7378,-119.7871', | |
| 'long beach': '33.7701,-118.1937', | |
| 'anaheim': '33.8366,-117.9143', | |
| 'riverside': '33.9533,-117.3962', | |
| 'stockton': '37.9577,-121.2908', | |
| 'bakersfield': '35.3733,-119.0187', | |
| # Additional major cities | |
| 'austin': '30.2672,-97.7431', | |
| 'nashville': '36.1627,-86.7816', | |
| 'memphis': '35.1495,-90.0490', | |
| 'milwaukee': '43.0389,-87.9065', | |
| 'kansas city': '39.0997,-94.5786', | |
| 'colorado springs': '38.8339,-104.8214', | |
| 'virginia beach': '36.8529,-75.9780', | |
| 'indianapolis': '39.7684,-86.1581', | |
| 'charlotte': '35.2271,-80.8431', | |
| 'jacksonville': '30.3322,-81.6557', | |
| 'columbus': '39.9612,-82.9988', | |
| 'fort worth': '32.7555,-97.3308', | |
| 'san antonio': '29.4241,-98.4936', | |
| 'el paso': '31.7619,-106.4850' | |
| } |