I am getting output error after Gradio deployment

37 views Asked by At

I am deploying ml model using Gradio, after deploying on Gradio I get error after I input and output shows error

code for this output is

import gradio as gr
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler, MinMaxScaler

# Sample data (replace this with your actual data)
X_train = np.array([[230.1, 37.8, 69.2],
                    [44.5, 39.3, 45.1],
                    [17.2, 45.9, 69.3],
                    [151.5, 41.3, 58.5],
                    [180.8, 10.8, 58.4]])
y_train = np.array([22.1, 10.4, 9.3, 18.5, 12.9])

# Initialize and train your Linear Regression model
scaler = MinMaxScaler()
scaler.fit(X_train) 
X_train_scale = scaler.transform(X_train)  

lm = LinearRegression()
lm.fit(X_train_scale, y_train)

# Define prediction function
def predict_sales(tv, radio, newspaper):
    # Scale the input features
    input_features = scaler.transform([[tv, radio, newspaper]])
    # Predict sales
    prediction = lm.predict(input_features)
    return prediction[0]

# Create Gradio Interface
tv_input = gr.Number(label="TV")
radio_input = gr.Number(label="Radio")
newspaper_input = gr.Number(label="Newspaper")
output_text = gr.Textbox(label="Predicted Sales")

gr.Interface(fn=predict_sales, 
             inputs=[tv_input, radio_input, newspaper_input], 
             outputs=output_text,
             title="Sales Prediction",
             description="Enter advertising expenses to predict sales",
            debug=True,enable_queue=True).launch()

]

enter image description here How do I solve this error?

0

There are 0 answers