Spaces:
Sleeping
Sleeping
| """MrrrMe Backend - GPU Fixes and Patches""" | |
| import os | |
| import logging | |
| # ===== GPU FIX: Patch TensorBoard ===== | |
| class DummySummaryWriter: | |
| """Dummy TensorBoard writer to prevent GPU issues""" | |
| def __init__(self, *args, **kwargs): | |
| pass | |
| def __getattr__(self, name): | |
| return lambda *args, **kwargs: None | |
| def patch_tensorboard(): | |
| """Patch TensorBoard to avoid GPU conflicts""" | |
| try: | |
| import tensorboardX | |
| tensorboardX.SummaryWriter = DummySummaryWriter | |
| print("[Patches] β TensorBoard patched") | |
| except ImportError: | |
| pass # TensorBoard not installed | |
| # ===== GPU FIX: Patch Logging to redirect /work paths ===== | |
| _original_FileHandler = logging.FileHandler | |
| class RedirectingFileHandler(_original_FileHandler): | |
| """File handler that redirects /work paths to /tmp""" | |
| def __init__(self, filename, mode='a', encoding=None, delay=False, errors=None): | |
| if isinstance(filename, str) and filename.startswith('/work'): | |
| filename = '/tmp/openface_log.txt' | |
| # Ensure directory exists | |
| dirname = os.path.dirname(filename) | |
| if dirname: | |
| os.makedirs(dirname, exist_ok=True) | |
| else: | |
| os.makedirs('/tmp', exist_ok=True) | |
| super().__init__(filename, mode, encoding, delay, errors) | |
| def patch_logging(): | |
| """Patch logging FileHandler to redirect paths""" | |
| logging.FileHandler = RedirectingFileHandler | |
| print("[Patches] β Logging FileHandler patched") | |
| def apply_all_patches(): | |
| """Apply all GPU and system patches""" | |
| patch_tensorboard() | |
| patch_logging() | |