11
11
12
12
import requests
13
13
from requests .adapters import HTTPAdapter
14
- from swankit .core import MediaBuffer
15
- from swankit .log import FONT
14
+ from rich .status import Status
16
15
from urllib3 .util .retry import Retry
17
16
18
17
from swanlab .error import NetworkError , ApiError
19
18
from swanlab .log import swanlog
20
19
from swanlab .package import get_package_version
20
+ from swanlab .toolkit import MediaBuffer
21
21
from .cos import CosClient
22
22
from .model import ProjectInfo , ExperimentInfo
23
23
from .. import auth
@@ -255,8 +255,7 @@ def mount_project(self, name: str, username: str = None, public: bool = None):
255
255
:param public: 项目是否公开
256
256
:return: 项目信息
257
257
"""
258
-
259
- def _ ():
258
+ with Status ("Getting project..." , spinner = "dots" ):
260
259
try :
261
260
data = {"name" : name }
262
261
if username is not None :
@@ -294,9 +293,7 @@ def _():
294
293
self .__groupname = resp ['username' ]
295
294
# 获取详细信息
296
295
resp = self .get (f"/project/{ self .groupname } /{ name } " )
297
- return ProjectInfo (resp )
298
-
299
- project : ProjectInfo = FONT .loading ("Getting project..." , _ )
296
+ project = ProjectInfo (resp )
300
297
self .__proj = project
301
298
302
299
def mount_exp (self , exp_name , colors : Tuple [str , str ], description : str = None , tags : List [str ] = None ):
@@ -307,11 +304,7 @@ def mount_exp(self, exp_name, colors: Tuple[str, str], description: str = None,
307
304
:param description: 实验描述
308
305
:param tags: 实验标签
309
306
"""
310
-
311
- def _ ():
312
- """
313
- 先创建实验,后生成cos凭证
314
- """
307
+ with Status ("Getting experiment..." , spinner = "dots" ):
315
308
post_data = {
316
309
"name" : exp_name ,
317
310
"colors" : list (colors ),
@@ -326,21 +319,15 @@ def _():
326
319
# 获取cos信息
327
320
self .__get_cos ()
328
321
329
- FONT .loading ("Creating experiment..." , _ )
330
-
331
322
def update_state (self , success : bool ):
332
323
"""
333
324
更新实验状态
334
325
:param success: 实验是否成功
335
326
"""
336
-
337
- def _ ():
338
- self .put (
339
- f"/project/{ self .groupname } /{ self .projname } /runs/{ self .exp_id } /state" ,
340
- {"state" : "FINISHED" if success else "CRASHED" , "from" : "sdk" },
341
- )
342
-
343
- FONT .loading ("Updating experiment status..." , _ )
327
+ self .put (
328
+ f"/project/{ self .groupname } /{ self .projname } /runs/{ self .exp_id } /state" ,
329
+ {"state" : "FINISHED" if success else "CRASHED" , "from" : "sdk" },
330
+ )
344
331
345
332
346
333
client : Optional ["Client" ] = None
0 commit comments