import gradio as gr import joblib import numpy as np # Load the saved model model = joblib.load('best_model.pkl') # Load the saved pipeline (which includes the scaler and the model) pipeline = joblib.load('best_pipeline.pkl') # Define the prediction function def predict(input1, input2, input3, input4, input5,input6): # Create a numpy array from the inputs inputs = np.array([input1, input2, input3, input4, input5,input6]).reshape(1, -1) # Transform the inputs using the scaler inputs_scaled = pipeline.transform(inputs) # Make the prediction prediction = model.predict(inputs_scaled) # Return the prediction and a description return prediction[0], f"The predicted value is {prediction[0]:.2f}" # Define the Gradio interface iface = gr.Interface( fn=predict, # Function to call inputs=[ gr.Number(label="Age"), gr.Number(label="Hours per day"), gr.Number(label="Depression"), gr.Number(label="Insomnia"), gr.Number(label="OCD"), gr.Number(label="BPM") ], outputs=[ gr.Number(label="Predicted Value"), gr.Textbox(label="Prediction Description") ], title="Music & Mental Health Predictor", description="""This Model has been trained on this Dataset.""", theme=gr.themes.Soft(), examples=[[18,3,0,1,0,156]] ) # Launch the interface iface.launch(debug=True)