mirror of
https://github.com/modelscope/modelscope.git
synced 2025-12-15 15:57:42 +01:00
Fix: filter existing files (.gitattributes/configuration.json/README.md)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user