import os import yaml import json import re import shutil from urllib.parse import quote, urlparse from pathlib import Path # Temel dizin ve checkpoint dizini sabit olarak tanımlanıyor BASE_DIR = os.path.dirname(os.path.abspath(__file__)) CHECKPOINT_DIR = os.path.join(BASE_DIR, 'ckpts') CUSTOM_MODELS_FILE = os.path.join(BASE_DIR, 'assets', 'custom_models.json') def fix_huggingface_url(url): """Convert Hugging Face blob URLs to raw/resolve URLs. Hugging Face has two URL formats: - /blob/ URLs show the web page (HTML) - WRONG for downloading - /resolve/ URLs provide the raw file content - CORRECT for downloading This function converts blob URLs to resolve URLs automatically. Args: url: The URL to fix Returns: The corrected URL (or original if not a HF blob URL) """ if not url: return url # Check if it's a Hugging Face URL with /blob/ if 'huggingface.co' in url and '/blob/' in url: fixed_url = url.replace('/blob/', '/resolve/') return fixed_url return url def validate_yaml_content(content, filepath=None): """Validate that content is YAML and not HTML. Args: content: The file content to validate filepath: Optional filepath for error messages Returns: tuple: (is_valid: bool, error_message: str or None) """ # Check if content looks like HTML html_indicators = [ '', '
', '