File size: 1,493 Bytes
0841889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 <a href="https://www.kaggle.com/datasets/catherinerasgaitis/mxmh-survey-results">Dataset</a>.""",
    theme=gr.themes.Soft(),
    examples=[[18,3,0,1,0,156]]
)

# Launch the interface
iface.launch(debug=True)