Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
# Load the saved model
|
6 |
+
model = joblib.load('best_model.pkl')
|
7 |
+
|
8 |
+
# Load the saved pipeline (which includes the scaler and the model)
|
9 |
+
pipeline = joblib.load('best_pipeline.pkl')
|
10 |
+
|
11 |
+
# Define the prediction function
|
12 |
+
def predict(input1, input2, input3, input4, input5,input6):
|
13 |
+
# Create a numpy array from the inputs
|
14 |
+
inputs = np.array([input1, input2, input3, input4, input5,input6]).reshape(1, -1)
|
15 |
+
|
16 |
+
# Transform the inputs using the scaler
|
17 |
+
inputs_scaled = pipeline.transform(inputs)
|
18 |
+
|
19 |
+
# Make the prediction
|
20 |
+
prediction = model.predict(inputs_scaled)
|
21 |
+
|
22 |
+
# Return the prediction and a description
|
23 |
+
return prediction[0], f"The predicted value is {prediction[0]:.2f}"
|
24 |
+
|
25 |
+
# Define the Gradio interface
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=predict, # Function to call
|
28 |
+
inputs=[
|
29 |
+
gr.Number(label="Age"),
|
30 |
+
gr.Number(label="Hours per day"),
|
31 |
+
gr.Number(label="Depression"),
|
32 |
+
gr.Number(label="Insomnia"),
|
33 |
+
gr.Number(label="OCD"),
|
34 |
+
gr.Number(label="BPM")
|
35 |
+
],
|
36 |
+
outputs=[
|
37 |
+
gr.Number(label="Predicted Value"),
|
38 |
+
gr.Textbox(label="Prediction Description")
|
39 |
+
],
|
40 |
+
title="Music & Mental Health Predictor",
|
41 |
+
description="This Model has been trained on this <a href="https://www.kaggle.com/datasets/catherinerasgaitis/mxmh-survey-results">Dataset</a>.",
|
42 |
+
theme=gr.themes.Soft(),
|
43 |
+
examples=[[18,3,0,1,0,156]]
|
44 |
+
)
|
45 |
+
|
46 |
+
# Launch the interface
|
47 |
+
iface.launch(debug=True)
|