Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions modelscope/hub/utils/aigc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def __init__(self,
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
Expand Down Expand Up @@ -125,6 +127,30 @@ def _process_model_path(self):
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
Expand Down
Loading