Slackbot
01/23/2024, 6:06 PMJian Shen Yap
01/24/2024, 2:48 AMChris
01/24/2024, 6:51 AMJian Shen Yap
01/24/2024, 6:53 AMChris
01/24/2024, 6:56 AMJian Shen Yap
01/24/2024, 7:04 AM__name__ and __qualname__
def base_function():
print("Hello from the base function")
def create_function_with_closure(new_name):
def closure():
return base_function()
closure.__name__ = new_name
closure.__qualname__ = new_name
return closure
# Create a new function with a dynamic name
dynamic_func = create_function_with_closure("dynamic_func")
print(dynamic_func.__name__) # Outputs: dynamic_func
dynamic_func() # Calls the base_functionChris
01/24/2024, 7:07 AMJian Shen Yap
01/24/2024, 7:09 AMChris
01/24/2024, 7:11 AMChris
01/24/2024, 7:15 AMTalha Yousuf
01/24/2024, 2:09 PMTalha Yousuf
01/24/2024, 2:10 PMChris
01/24/2024, 2:36 PMdef setMethod(anomaly_runner: Runner, preprocess: Preprocess):
async def predict_image(f: Image) -> list[InferenceDefect]:
# do stuff and return
return result
return predict_image
for idx, (runner, preprocess, fullname) in enumerate(zip(runner_list, preprocess_list, model_names)):
path = f"predict_image/{'/'.join(fullname.split('_')[:4])}"
fn = setMethod(anomaly_runner=runner, preprocess=preprocess, index=idx)
_api = InferenceAPI[IOType]( # Reuse code from bentoml Decorator
name=first_not_none(f"predict_image_{fullname}"),
user_defined_callback=fn,
input_descriptor=Image(),
output_descriptor=JSON(),
doc=None,
route=path,
)
if _api.name in svc.apis:
raise BentoMLException(
f"API {_api.name} is already defined in Service {svc.name}"
)
svc.apis[_api.name] = _apiChris
01/24/2024, 2:39 PMbentoml.bentos.build(svc, models=model_names) # svc is the bentoml.Service object
However, it seems the build needs a .py file with all the code and just passing the Service object does not work? Is this correct?
I do not know if generating python code to build a service is really a nice solution for such a automatized process...
@Talha Yousuf is that the reason why you used Jinja?Chris
01/24/2024, 3:54 PMJian Shen Yap
01/26/2024, 2:37 AMChris
02/10/2024, 11:10 AMChris
02/10/2024, 11:41 AMChris
02/10/2024, 12:31 PMJian Shen Yap
02/16/2024, 4:03 AM