Spaces:
Sleeping
Sleeping
| """ | |
| Hugging Face Spaces Configuration | |
| Handles environment detection and launch configuration for HF Spaces deployment | |
| """ | |
| import os | |
| def configure_hf_environment(): | |
| """ | |
| Check if running on Hugging Face Spaces and configure environment | |
| Returns True if running on HF Spaces, False otherwise | |
| """ | |
| # Check for HF Spaces environment variables | |
| if os.getenv("SPACE_ID") or os.getenv("HUGGINGFACE_SPACE"): | |
| print("π Detected Hugging Face Spaces environment") | |
| return True | |
| # Fallback check for common HF Spaces indicators | |
| if "huggingface.co" in os.getenv("SPACE_HOST", ""): | |
| print("π Detected Hugging Face Spaces environment (via SPACE_HOST)") | |
| return True | |
| # Check if we're in a Spaces-like environment | |
| if os.path.exists("/tmp") and os.getenv("HOME", "").startswith("/tmp"): | |
| print("π Likely running on Hugging Face Spaces") | |
| return True | |
| print("π§ Local development environment detected") | |
| return False | |
| def get_hf_launch_config(): | |
| """ | |
| Get launch configuration for Hugging Face Spaces | |
| Compatible with Gradio 4.20.0 - removed unsupported parameters | |
| Optimized for 150 concurrent users | |
| """ | |
| config = { | |
| "server_name": "0.0.0.0", | |
| "server_port": 7860, | |
| "share": False, | |
| "show_error": True, | |
| "quiet": False, | |
| "max_threads": 100 # Allow more worker threads for concurrent requests | |
| # Removed: show_tips, height, width, ssl_*, app_kwargs - not supported in 4.20.0 | |
| } | |
| print("βοΈ Using Hugging Face Spaces launch configuration (Gradio 4.20.0 compatible)") | |
| print("π Configured for 150 concurrent users with queue (max_size=200, concurrency=50)") | |
| return config | |