""" Deployment configuration for Gradio + MCP Server Supports two deployment modes: 1. Local mode: Gradio runs locally, GPU functions call Modal endpoints 2. Modal mode: Gradio runs on Modal, GPU functions run locally on Modal """ import os from enum import Enum from typing import Optional class DeploymentMode(Enum): LOCAL = "local" # Local Gradio + Remote GPU (Modal endpoints) MODAL = "modal" # Modal Gradio + Local GPU (Modal functions) # Get deployment mode from environment variable DEPLOYMENT_MODE = DeploymentMode(os.getenv("DEPLOYMENT_MODE", "local")) # Modal endpoints configuration MODAL_APP_NAME = "gradio-mcp-server" # Endpoint URLs (will be set when deployed) ENDPOINTS = { "transcribe_audio": None, # Will be filled with actual endpoint URL } def get_deployment_mode() -> DeploymentMode: """Get current deployment mode""" return DEPLOYMENT_MODE def is_local_mode() -> bool: """Check if running in local mode""" return DEPLOYMENT_MODE == DeploymentMode.LOCAL def is_modal_mode() -> bool: """Check if running in modal mode""" return DEPLOYMENT_MODE == DeploymentMode.MODAL def set_endpoint_url(endpoint_name: str, url: str): """Set endpoint URL for local mode""" global ENDPOINTS ENDPOINTS[endpoint_name] = url def get_endpoint_url(endpoint_name: str) -> Optional[str]: """Get endpoint URL for local mode""" return ENDPOINTS.get(endpoint_name) def get_transcribe_endpoint_url() -> Optional[str]: """Get transcription endpoint URL""" return get_endpoint_url("transcribe_audio") # Environment-specific cache directory def get_cache_dir() -> str: """Get cache directory based on deployment mode""" if is_modal_mode(): return "/root/cache" else: # Local mode - use user's home directory home_dir = os.path.expanduser("~") cache_dir = os.path.join(home_dir, ".gradio_mcp_cache") os.makedirs(cache_dir, exist_ok=True) return cache_dir # Auto-load endpoint configuration in local mode if is_local_mode(): import json config_file = "endpoint_config.json" if os.path.exists(config_file): try: with open(config_file, 'r') as f: config = json.load(f) for endpoint_name, url in config.items(): set_endpoint_url(endpoint_name, url) print(f"✅ Loaded endpoint configuration from {config_file}") except Exception as e: print(f"⚠️ Failed to load endpoint configuration: {e}") else: print(f"⚠️ No endpoint configuration found. Run 'python deploy_endpoints.py deploy' first.") print(f"🚀 Deployment mode: {DEPLOYMENT_MODE.value}") print(f"📁 Cache directory: {get_cache_dir()}")