8
8
from typing import Annotated , Optional
9
9
from emd .sdk .status import get_model_status
10
10
from rich .table import Table
11
+ from rich .panel import Panel
12
+ from rich .box import Box , SIMPLE , MINIMAL
11
13
from emd .utils .decorators import catch_aws_credential_errors ,check_emd_env_exist ,load_aws_profile
12
14
from emd .constants import MODEL_DEFAULT_TAG
13
15
from emd .utils .logger_utils import make_layout
@@ -31,7 +33,7 @@ def status(
31
33
str , typer .Argument (help = "Model tag" )
32
34
] = MODEL_DEFAULT_TAG ,
33
35
):
34
- ret = get_model_status (model_id ,model_tag = model_tag )
36
+ ret = get_model_status (model_id , model_tag = model_tag )
35
37
inprogress = ret ['inprogress' ]
36
38
completed = ret ['completed' ]
37
39
@@ -40,49 +42,84 @@ def status(
40
42
if d ['status' ] == "Stopped" :
41
43
continue
42
44
data .append ({
43
- "model_id" :d ['model_id' ],
44
- "model_tag" :d ['model_tag' ],
45
+ "model_id" : d ['model_id' ],
46
+ "model_tag" : d ['model_tag' ],
45
47
"status" : f"{ d ['status' ]} ({ d ['stage_name' ]} )" ,
46
- "service_type" :d ['service_type' ],
47
- "instance_type" :d ['instance_type' ],
48
- "create_time" :d ['create_time' ],
49
- "outputs" :d ['outputs' ],
48
+ "service_type" : d ['service_type' ],
49
+ "instance_type" : d ['instance_type' ],
50
+ "create_time" : d ['create_time' ],
51
+ "outputs" : d ['outputs' ],
50
52
})
51
53
52
54
for d in completed :
53
55
data .append ({
54
- "model_id" :d ['model_id' ],
55
- "model_tag" :d ['model_tag' ],
56
+ "model_id" : d ['model_id' ],
57
+ "model_tag" : d ['model_tag' ],
56
58
"status" : d ['stack_status' ],
57
- "service_type" :d ['service_type' ],
58
- "instance_type" :d ['instance_type' ],
59
- "create_time" :d ['create_time' ],
60
- "outputs" :d ['outputs' ],
59
+ "service_type" : d ['service_type' ],
60
+ "instance_type" : d ['instance_type' ],
61
+ "create_time" : d ['create_time' ],
62
+ "outputs" : d ['outputs' ],
61
63
})
62
64
63
65
account_id = get_account_id ()
64
- table = Table (show_lines = True , expand = True )
65
- table .add_column ("ModelId" , justify = "left" ,overflow = 'fold' )
66
- table .add_column ("ModelTag" , justify = "left" ,overflow = 'fold' )
67
- table .add_column ("Status" , justify = "left" ,overflow = 'fold' )
68
- table .add_column ("Service" , justify = "left" ,overflow = 'fold' ,max_width = 19 )
69
- table .add_column ("Instance" , justify = "left" ,overflow = 'fold' )
70
- table .add_column ("CreateTime" , justify = "left" ,overflow = 'fold' )
71
- table .add_column ("Outputs" , justify = "left" ,overflow = 'fold' )
72
-
73
- # table.field_names = ["model_id", "status"]
74
- for d in data :
75
- table .add_row (
76
- d ['model_id' ],
77
- d ['model_tag' ],
78
- d ['status' ],
79
- d ['service_type' ],
80
- d ['instance_type' ],
81
- d ['create_time' ].replace (" " , "\n " ),
82
- d ['outputs' ]
83
- )
84
- # table.add_row([d['model_id'], d['status']])
85
- console .print (table )
66
+
67
+ # Display each model in its own table box
68
+ for model_data in data :
69
+ # Create a table for the model with a thinner border
70
+ model_table = Table (show_header = False , expand = True )
71
+
72
+ # Add a single column for the model name header
73
+ model_table .add_column (justify = "center" )
74
+
75
+ # Add the model name as the first row with bold styling
76
+ model_name = f"{ model_data ['model_id' ]} /{ model_data ['model_tag' ]} "
77
+ model_table .add_row (model_name , style = "bold" )
78
+
79
+ # Create a nested table for model details
80
+ details_table = Table (show_header = False , box = None , expand = True )
81
+ details_table .add_column (justify = "left" , style = "cyan" , width = 20 )
82
+ details_table .add_column (justify = "left" , overflow = "fold" )
83
+
84
+ # Add model details as name/value pairs
85
+ details_table .add_row ("Status" , model_data ['status' ])
86
+ details_table .add_row ("Service Type" , model_data ['service_type' ])
87
+ details_table .add_row ("Instance Type" , model_data ['instance_type' ])
88
+ details_table .add_row ("Create Time" , model_data ['create_time' ])
89
+
90
+ # Parse and add outputs as separate rows
91
+ try :
92
+ # Check if outputs is a string that looks like a dictionary
93
+ if model_data ['outputs' ] and isinstance (model_data ['outputs' ], str ) and '{' in model_data ['outputs' ]:
94
+ # Try to convert the string to a dictionary
95
+ import ast
96
+ outputs_dict = ast .literal_eval (model_data ['outputs' ])
97
+ if isinstance (outputs_dict , dict ):
98
+ # Define the order of priority keys
99
+ priority_keys = ["BaseURL" , "Model" , "ModelAPIKey" ]
100
+
101
+ # First add priority keys if they exist
102
+ for key in priority_keys :
103
+ if key in outputs_dict :
104
+ details_table .add_row (key , str (outputs_dict [key ]))
105
+
106
+ # Then add any remaining keys
107
+ for key , value in outputs_dict .items ():
108
+ if key not in priority_keys :
109
+ details_table .add_row (key , str (value ))
110
+ else :
111
+ details_table .add_row ("Outputs" , model_data ['outputs' ])
112
+ else :
113
+ details_table .add_row ("Outputs" , model_data ['outputs' ])
114
+ except (SyntaxError , ValueError ):
115
+ # If parsing fails, just show the raw outputs
116
+ details_table .add_row ("Outputs" , model_data ['outputs' ])
117
+
118
+ # Add the details table as a row in the main table
119
+ model_table .add_row (details_table )
120
+
121
+ console .print (model_table )
122
+ console .print () # Add a blank line between models
86
123
87
124
88
125
if __name__ == "__main__" :
0 commit comments