1919import itables
2020import pandas
2121import logging
22+ import json
2223from botocore .config import Config
2324from ipywidgets import Button , Output
2425from IPython .display import display
@@ -160,6 +161,7 @@ def _get_model_summary(self, full_summary):
160161 "Model Type" : model_type ,
161162 "Model Description" : full_summary ["HubContentDescription" ],
162163 "Search Keywords" : keywords ,
164+ "Deployment Configs" : self ._create_config_link (full_summary ["HubContentName" ]),
163165 }
164166
165167 def _determine_model_type (self , keywords , model_id ):
@@ -180,6 +182,77 @@ def _get_hub_document(self, model_id):
180182 HubContentType = "Model" ,
181183 HubContentName = model_id
182184 )["HubContentDocument" ]
185+
186+ def _get_supported_instance_types (self , model_id ):
187+ """Extract supported instance types from hub document."""
188+ try :
189+ hub_doc = self ._get_hub_document (model_id )
190+ doc_data = json .loads (hub_doc )
191+
192+ supported_types = doc_data .get ("SupportedInferenceInstanceTypes" , [])
193+ default_type = doc_data .get ("DefaultInferenceInstanceType" )
194+
195+ if default_type and default_type in supported_types :
196+ supported_types = [default_type ] + [t for t in supported_types if t != default_type ]
197+
198+ return {"types" : supported_types , "default" : default_type , "error" : None }
199+ except Exception as e :
200+ return {"types" : [], "default" : None , "error" : str (e )}
201+
202+ def _create_config_link (self , model_id ):
203+ """Create deployment config display."""
204+ try :
205+ # Try to detect if we're in a Jupyter environment that supports JavaScript
206+ from IPython import get_ipython
207+ ipython = get_ipython ()
208+ if ipython and 'ipykernel' in str (type (ipython )):
209+ config_code = self ._generate_deployment_config (model_id ).replace ('\n ' , '\\ n' ).replace ("'" , "\\ '" )
210+ return f'<a href="#" onclick="navigator.clipboard.writeText(\' { config_code } \' ); alert(\' Config copied to clipboard!\' ); return false;" style="color: #007bff; text-decoration: underline;">Get SDK Config</a>'
211+ except :
212+ pass
213+
214+ # Fallback: display config directly
215+ return f'<details><summary style="color: #007bff; cursor: pointer;">Get SDK Config</summary><pre style="font-size: 10px; background: #f5f5f5; padding: 5px; margin: 5px 0;">{ self ._generate_deployment_config (model_id )} </pre></details>'
216+
217+ def _generate_deployment_config (self , model_id ):
218+ """Generate deployment configuration code for a model."""
219+ instance_data = self ._get_supported_instance_types (model_id )
220+ supported_types = instance_data ["types" ]
221+ default_type = instance_data ["default" ]
222+ error = instance_data ["error" ]
223+
224+ if error :
225+ instance_type = '<ENTER-INSTANCE-TYPE>'
226+ types_comment = ""
227+ else :
228+ instance_type = default_type if default_type else '<ENTER-INSTANCE-TYPE>'
229+ types_comment = f"# Supported instance types: { ', ' .join (supported_types )} " if supported_types else "# No supported instance types found"
230+
231+ config_code = f'''# Deployment configuration for { model_id }
232+ from sagemaker.hyperpod.inference.config.hp_jumpstart_endpoint_config import Model, Server, SageMakerEndpoint
233+ from sagemaker.hyperpod.inference.hp_jumpstart_endpoint import HPJumpStartEndpoint
234+
235+ { types_comment }
236+
237+ # Create configs - REPLACE PLACEHOLDER VALUE BELOW
238+ model = Model(
239+ model_id='{ model_id } ',
240+ )
241+ server = Server(
242+ instance_type='{ instance_type } ',
243+ )
244+ endpoint_name = SageMakerEndpoint(name='<ENTER-YOUR-ENDPOINT-NAME>')
245+
246+ # Create endpoint spec
247+ js_endpoint = HPJumpStartEndpoint(
248+ model=model,
249+ server=server,
250+ sage_maker_endpoint=endpoint_name,
251+ )
252+
253+ # Deploy the endpoint
254+ js_endpoint.create()'''
255+ return config_code
183256
184257
185258def get_all_public_hub_model_data (region : str ):
@@ -198,7 +271,7 @@ def interactive_view(tabular_data: list):
198271 styled_df = _style_dataframe (df )
199272 layout = _get_table_layout (len (tabular_data ))
200273
201- itables .show (styled_df , layout = layout )
274+ itables .show (styled_df , layout = layout , allow_html = True )
202275
203276
204277def _configure_itables ():
0 commit comments