IDAgentsFreshTest / hf_config.py
IDAgents Developer
Configure Gradio queue for 150 concurrent users
16142f3
raw
history blame
1.76 kB
"""
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