MilanM commited on
Commit
756f1ff
·
verified ·
1 Parent(s): 8ad14f1

Update main_app.py

Browse files
Files changed (1) hide show
  1. main_app.py +15 -4
main_app.py CHANGED
@@ -425,7 +425,7 @@ def _(function_editor, mo, os):
425
  try:
426
  return __import__(name, *args, **kwargs)
427
  except ImportError:
428
- # Return a dummy module
429
  class DummyModule:
430
  _instance = None
431
 
@@ -440,8 +440,19 @@ def _(function_editor, mo, os):
440
  def __call__(self, *args, **kwargs):
441
  return self
442
 
 
 
 
 
 
 
 
 
 
 
 
443
  return DummyModule()
444
-
445
  # Create a namespace to execute the code in
446
  namespace = {'__builtins__': __builtins__, '__import__': safe_import}
447
  # Execute the code
@@ -796,7 +807,7 @@ def _(
796
  # If JSON parsing fails, try Python literal evaluation as fallback
797
  function_meta[deployment_client.repository.FunctionMetaNames.SAMPLE_SCORING_INPUT] = ast.literal_eval(sample_input_editor.value)
798
 
799
- def upload_function(function_meta, use_function_object=False):
800
  """
801
  Uploads a Python function to watsonx.ai as a deployable asset.
802
  Parameters:
@@ -863,7 +874,7 @@ def _(
863
 
864
  upload_button = mo.ui.button(
865
  label="Upload Function",
866
- on_click=lambda _: upload_function(function_meta, use_function_object=False),
867
  kind="success",
868
  tooltip="Click to upload function to watsonx.ai"
869
  )
 
425
  try:
426
  return __import__(name, *args, **kwargs)
427
  except ImportError:
428
+ # Return a dummy module with singleton pattern
429
  class DummyModule:
430
  _instance = None
431
 
 
440
  def __call__(self, *args, **kwargs):
441
  return self
442
 
443
+ # Add to sys.modules to handle nested imports
444
+ import sys
445
+ if '.' in name:
446
+ parts = name.split('.')
447
+ for i in range(1, len(parts) + 1):
448
+ submod_name = '.'.join(parts[:i])
449
+ if submod_name not in sys.modules:
450
+ sys.modules[submod_name] = DummyModule()
451
+ else:
452
+ sys.modules[name] = DummyModule()
453
+
454
  return DummyModule()
455
+
456
  # Create a namespace to execute the code in
457
  namespace = {'__builtins__': __builtins__, '__import__': safe_import}
458
  # Execute the code
 
807
  # If JSON parsing fails, try Python literal evaluation as fallback
808
  function_meta[deployment_client.repository.FunctionMetaNames.SAMPLE_SCORING_INPUT] = ast.literal_eval(sample_input_editor.value)
809
 
810
+ def upload_function(function_meta, use_function_object=True):
811
  """
812
  Uploads a Python function to watsonx.ai as a deployable asset.
813
  Parameters:
 
874
 
875
  upload_button = mo.ui.button(
876
  label="Upload Function",
877
+ on_click=lambda _: upload_function(function_meta, use_function_object=True),
878
  kind="success",
879
  tooltip="Click to upload function to watsonx.ai"
880
  )