MCPcopy Create free account
hub / github.com/modelscope/ms-agent / push

Method push

ms_agent/utils/push_to_hub.py:437–489  ·  view source on GitHub ↗

Push files from a local directory to the ModelScope repository. Args: repo_id (str): The ModelScope repository ID in the format 'namespace/repo_name'. For example, 'my_namespace/my_model'. folder_path (str): The local directory containing fil

(
        self,
        *,
        repo_id: str,
        folder_path: str,
        path_in_repo: Optional[str] = None,
        repo_type: Optional[str] = 'model',
        commit_message: Optional[str] = None,
        exclude: Optional[List[str]] = None,
        add_powered_by: Optional[bool] = True,
    )

Source from the content-addressed store, hash-verified

435 )
436
437 def push(
438 self,
439 *,
440 repo_id: str,
441 folder_path: str,
442 path_in_repo: Optional[str] = None,
443 repo_type: Optional[str] = 'model',
444 commit_message: Optional[str] = None,
445 exclude: Optional[List[str]] = None,
446 add_powered_by: Optional[bool] = True,
447 ):
448 """
449 Push files from a local directory to the ModelScope repository.
450
451 Args:
452 repo_id (str): The ModelScope repository ID in the format 'namespace/repo_name'.
453 For example, 'my_namespace/my_model'.
454 folder_path (str): The local directory containing files to upload.
455 path_in_repo (Optional[str]): The relative path in the repository where files should be stored.
456 Defaults to the root of the repository.
457 repo_type (Optional[str]): Type of the repository, either 'model' or 'dataset'. Defaults to 'model'.
458 commit_message (Optional[str]): The commit message for the upload. Defaults to a generic message.
459 exclude (Optional[List[str]]): List of regex patterns to exclude files from upload. Defaults to None.
460 """
461 path_in_repo_replace = f'{path_in_repo.rstrip("/")}/' if path_in_repo else ''
462 path_in_repo_url: str = f'{self.endpoint}/{repo_type}s/{repo_id}/resolve/master/{path_in_repo_replace}'
463 origin_report, backup_report = self._preprocess(
464 folder_path=folder_path,
465 path_in_repo_url=path_in_repo_url,
466 add_powered_by=add_powered_by,
467 )
468
469 try:
470 self.api.upload_folder(
471 repo_id=repo_id,
472 folder_path=folder_path,
473 path_in_repo=path_in_repo,
474 commit_message=commit_message or f'Upload files to {repo_id}',
475 token=self.token,
476 ignore_patterns=exclude,
477 revision='master',
478 )
479 target_url: str = f'{self.endpoint}/{repo_type}s/{repo_id}/files'
480 logger.info(
481 f'Successfully pushed files to ModelScope: {target_url}')
482 except Exception as e:
483 logger.error(f'Failed to push files to ModelScope: {e}')
484 finally:
485 if origin_report and backup_report:
486 self._postprocess(
487 report_file_path=origin_report,
488 report_file_path_in_cache=backup_report,
489 )
490
491
492class PushToHuggingFace(PushToHub):

Callers

nothing calls this directly

Calls 2

_preprocessMethod · 0.95
_postprocessMethod · 0.95

Tested by

no test coverage detected