import gradio as gr from sklearn.multioutput import MultiOutputRegressor from sklearn.datasets import load_linnerud from sklearn.multioutput import MultiOutputRegressor from sklearn.linear_model import Ridge X, y = load_linnerud(return_X_y=True, as_frame=True) regr = MultiOutputRegressor(Ridge(random_state=123)).fit(X, y) # example usage: regr.predict(X.iloc[[0]]) iface = gr.Interface( title="MultiOutputRegressor Example", fn=regr.predict, inputs=gr.Dataframe( value=X.head(1), headers=list(X.columns), col_count=(X.shape[1], "fixed"), row_count=(1, "dynamic"), datatype=X.dtypes.apply(str).replace("float64", "number").values.tolist(), ), outputs=gr.Numpy( value=regr.predict(X.head(1)), headers=list(y.columns), col_count=(y.shape[1], "fixed"), datatype=y.dtypes.apply(str).replace("float64", "number").values.tolist(), ), ) iface.launch() # %% Code Graveyard # def predict(X): # max_rows = 100000 # if X.shape[0] > max_rows: # raise ValueError( # f"Too many rows ({X.shape[0]}), please use less than {max_rows} rows." # ) # return regr.predict(X)