cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can we deploy a custom model

SandipCoder
New Contributor

Goal:
Let's say we have a custom function with arbitrary python code . And we want to deploy that as model as we wanted to generate an API endpoint .So that that can be accessed from external applications.

I am attaching the below code I have tried .If you know any better way to do this .Please suggest.

Sample Code I tried:

import mlflow
import mlflow.pyfunc
import pandas as pd
from mlflow.models.signature import infer_signature

class Model(mlflow.pyfunc.PythonModel):
def cust_func():
# Perform the SQL operation on the driver
sql_query_insert = f"""INSERT INTO {FULL_TABLE_NAME_FOR_LOAD} (type) SELECT 'Sandip'"""
spark.sql(sql_query_insert)

def predict(self, context, model_input):
cust_func()
return pd.DataFrame(["Done"], columns=["result"])

# Convert the input data to a pandas DataFrame
question = pd.DataFrame([{"question": "Please do your task"}])

with mlflow.start_run(run_name="A_run_created_from_notebook2") as run:
model = Model()
signature = infer_signature(question, model.predict(None, question))
mlflow.pyfunc.log_model("A_model_created_from_notebook2", python_model=model, signature=signature)

Error:

AT API endpoint if we pass request :
{"inputs" : "Please do the task"}

Nothing is coming out.
Error in console : 2024/08/25 05:25:08 WARNING mlflow.pyfunc.scoring_server: If using `instances` as input key, we internally convert the data type from `records` (List[Dict]) type to `list` (Dict[str, List]) type if the data is a pandas dataframe representation. This might cause schema changes. Please use `inputs` to avoid this converesion.

 

Sandip Bhowmick
0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group