BilalSardar commited on
Commit
260717a
·
verified ·
1 Parent(s): 8ec577a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -25
app.py CHANGED
@@ -2,29 +2,47 @@ 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"),
@@ -37,11 +55,80 @@ iface = gr.Interface(
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)
 
2
  import joblib
3
  import numpy as np
4
 
5
+ # Load the saved models and pipelines
6
+ anxiety_model = joblib.load('Anxiety_best_model.pkl')
7
+ anxiety_pipeline = joblib.load('Anxiety_best_pipeline.pkl')
8
+
9
+ depression_model = joblib.load('Depression_best_model.pkl')
10
+ depression_pipeline = joblib.load('Depression_best_pipeline.pkl')
11
+
12
+ insomnia_model = joblib.load('Insomnia_best_model.pkl')
13
+ insomnia_pipeline = joblib.load('Insomnia_best_pipeline.pkl')
14
+
15
+ ocd_model = joblib.load('OCD_best_model.pkl')
16
+ ocd_pipeline = joblib.load('OCD_best_pipeline.pkl')
17
+
18
+ # Define the prediction functions
19
+ def Anxiety_predict(input1, input2, input3, input4, input5, input6):
20
+ inputs = np.array([input1, input2, input3, input4, input5, input6]).reshape(1, -1)
21
+ inputs_scaled = anxiety_pipeline.transform(inputs)
22
+ prediction = anxiety_model.predict(inputs_scaled)
23
  return prediction[0], f"The predicted value is {prediction[0]:.2f}"
24
 
25
+ def Depression_predict(input1, input2, input3, input4, input5, input6):
26
+ inputs = np.array([input1, input2, input3, input4, input5, input6]).reshape(1, -1)
27
+ inputs_scaled = depression_pipeline.transform(inputs)
28
+ prediction = depression_model.predict(inputs_scaled)
29
+ return prediction[0], f"The predicted value is {prediction[0]:.2f}"
30
+
31
+ def Insomnia_predict(input1, input2, input3, input4, input5, input6):
32
+ inputs = np.array([input1, input2, input3, input4, input5, input6]).reshape(1, -1)
33
+ inputs_scaled = insomnia_pipeline.transform(inputs)
34
+ prediction = insomnia_model.predict(inputs_scaled)
35
+ return prediction[0], f"The predicted value is {prediction[0]:.2f}"
36
+
37
+ def OCD_predict(input1, input2, input3, input4, input5, input6):
38
+ inputs = np.array([input1, input2, input3, input4, input5, input6]).reshape(1, -1)
39
+ inputs_scaled = ocd_pipeline.transform(inputs)
40
+ prediction = ocd_model.predict(inputs_scaled)
41
+ return prediction[0], f"The predicted value is {prediction[0]:.2f}"
42
+
43
+ # Define the Gradio interfaces
44
+ anxiety_iface = gr.Interface(
45
+ fn=Anxiety_predict,
46
  inputs=[
47
  gr.Number(label="Age"),
48
  gr.Number(label="Hours per day"),
 
55
  gr.Number(label="Predicted Value"),
56
  gr.Textbox(label="Prediction Description")
57
  ],
58
+ title="Music & Mental Health Predictor - Anxiety",
59
+ description="Enter 5 numeric values to get a prediction.",
60
+ theme=gr.themes.Soft(),
61
+ examples=[[18, 3, 0, 1, 0, 156]]
62
+ )
63
+ depression_iface = gr.Interface(
64
+ fn=Depression_predict,
65
+ inputs=[
66
+ gr.Number(label="Age"),
67
+ gr.Number(label="Hours per day"),
68
+ gr.Number(label="Insomnia"),
69
+ gr.Number(label="Anxiety"),
70
+ gr.Number(label="OCD"),
71
+ gr.Number(label="BPM")
72
+ ],
73
+ outputs=[
74
+ gr.Number(label="Predicted Value"),
75
+ gr.Textbox(label="Prediction Description")
76
+ ],
77
+ title="Music & Mental Health Predictor - Depression",
78
+ description="Enter 5 numeric values to get a prediction.",
79
  theme=gr.themes.Soft(),
80
+ examples=[[18, 3, 0, 1, 0, 156]]
81
  )
82
+ insomnia_iface = gr.Interface(
83
+ fn=Insomnia_predict,
84
+ inputs=[
85
+ gr.Number(label="Age"),
86
+ gr.Number(label="Hours per day"),
87
+ gr.Number(label="Depression"),
88
+ gr.Number(label="Anxiety"),
89
+ gr.Number(label="OCD"),
90
+ gr.Number(label="BPM")
91
+ ],
92
+ outputs=[
93
+ gr.Number(label="Predicted Value"),
94
+ gr.Textbox(label="Prediction Description")
95
+ ],
96
+ title="Music & Mental Health Predictor - Insomnia",
97
+ description="Enter 5 numeric values to get a prediction.",
98
+ theme=gr.themes.Soft(),
99
+ examples=[[18, 3, 0, 1, 0, 156]]
100
+ )
101
+
102
+ ocd_iface = gr.Interface(
103
+ fn=OCD_predict,
104
+ inputs=[
105
+ gr.Number(label="Age"),
106
+ gr.Number(label="Hours per day"),
107
+ gr.Number(label="Insomnia"),
108
+ gr.Number(label="Anxiety"),
109
+ gr.Number(label="Depression"),
110
+ gr.Number(label="BPM")
111
+ ],
112
+ outputs=[
113
+ gr.Number(label="Predicted Value"),
114
+ gr.Textbox(label="Prediction Description")
115
+ ],
116
+ title="Music & Mental Health Predictor - OCD",
117
+ description="Enter 5 numeric values to get a prediction.",
118
+ theme=gr.themes.Soft(),
119
+ examples=[[18, 3, 0, 1, 0, 156]]
120
+ )
121
+
122
+ # Create a tabbed interface
123
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
124
+ with gr.Tab("Anxiety"):
125
+ anxiety_iface.render()
126
+ with gr.Tab("Depression"):
127
+ depression_iface.render()
128
+ with gr.Tab("Insomnia"):
129
+ insomnia_iface.render()
130
+ with gr.Tab("OCD"):
131
+ ocd_iface.render()
132
 
133
  # Launch the interface
134
+ demo.launch(debug=True)