Spaces:
Paused
Paused
| """ | |
| SSL Configuration | |
| Configures SSL context to use certifi certificates for reliable | |
| model downloads across different platforms (especially macOS). | |
| """ | |
| import logging | |
| import ssl | |
| import certifi | |
| logger = logging.getLogger(__name__) | |
| def configure_ssl_context() -> None: | |
| """ | |
| Configure SSL context to use certifi certificates. | |
| This resolves SSL certificate verification issues on macOS when | |
| downloading models via torch.hub or HuggingFace Hub. | |
| Should be called once at application startup before any network operations. | |
| Note: | |
| This function is idempotent - safe to call multiple times. | |
| """ | |
| try: | |
| ssl_context = ssl.create_default_context(cafile=certifi.where()) | |
| ssl._create_default_https_context = lambda: ssl_context | |
| logger.info("SSL context configured with certifi certificates") | |
| except Exception as e: | |
| logger.warning(f"Failed to configure SSL context: {e}") | |
| # Don't fail startup, just log warning | |
| # Application may still work in some environments | |