| 135 | return self.api.get_model_url(self.model_id) |
| 136 | |
| 137 | def push_model(self, tpl_dir='readme.tpl'): |
| 138 | from modelscope.hub.repository import Repository |
| 139 | if self.args.version_tag and self.args.version_info: |
| 140 | clone_dir = tempfile.TemporaryDirectory().name |
| 141 | repo = Repository(clone_dir, clone_from=self.model_id) |
| 142 | repo.tag_and_push(self.args.version_tag, self.args.version_info) |
| 143 | shutil.rmtree(clone_dir) |
| 144 | else: |
| 145 | cfg_file = os.path.join(self.args.model_dir, 'README.md') |
| 146 | if not os.path.exists(cfg_file): |
| 147 | with open(os.path.join(template_path, |
| 148 | tpl_dir)) as tpl_file_path: |
| 149 | tpl = Template(tpl_file_path.read()) |
| 150 | f = open(cfg_file, 'w') |
| 151 | f.write(tpl.substitute(model_id=self.model_id)) |
| 152 | f.close() |
| 153 | self.api.push_model( |
| 154 | model_id=self.model_id, |
| 155 | model_dir=self.args.model_dir, |
| 156 | visibility=self.args.visibility, |
| 157 | license=self.args.license, |
| 158 | chinese_name=self.args.chinese_name) |
| 159 | self.pprint() |
| 160 | |
| 161 | def pprint(self): |
| 162 | logger.info('>>> Clone the model_git < %s >, commit and push it.' |