Fix: filter existing files (.gitattributes/configuration.json/README.md)

This commit is contained in:
Koko-ry
2025-08-14 16:06:57 +08:00
committed by GitHub
parent 7d11b77112
commit 7bb94a3cf1

View File

@@ -75,6 +75,8 @@ class AigcModel:
cover_images (List[str], optional): List of cover image URLs.
base_model_id (str, optional): Base model name. e.g., 'AI-ModelScope/FLUX.1-dev'.
path_in_repo (str, optional): Path in the repository.
Note: Auto-upload during AIGC create is temporarily disabled by server. This parameter
will not take effect at creation time.
"""
self.model_path = model_path
self.aigc_type = aigc_type
@@ -125,6 +127,30 @@ class AigcModel:
target_file = self.model_path
logger.info('Using file: %s', os.path.basename(target_file))
elif os.path.isdir(self.model_path):
# Validate top-level directory: it must not be empty; and if it has files,
# they must not be only the common placeholder files
top_entries = os.listdir(self.model_path)
if len(top_entries) == 0:
raise ValueError(
f'Directory is empty: {self.model_path}. '
f'Please place at least one model file at the top level (e.g., .safetensors/.pth/.bin).'
)
top_files = [
name for name in top_entries
if os.path.isfile(os.path.join(self.model_path, name))
]
placeholder_names = {
'.gitattributes', 'configuration.json', 'readme.md'
}
if top_files:
normalized = {name.lower() for name in top_files}
if normalized.issubset(placeholder_names):
raise ValueError(
'Top-level directory contains only [.gitattributes, configuration.json, README.md]. '
'Please place additional model files at the top level (e.g., .safetensors/.pth/.bin).'
)
# Priority order for metadata file: safetensors -> pth -> bin -> first file
file_extensions = ['.safetensors', '.pth', '.bin']
target_file = None