Jobanjps commited on
Commit
3f6fa4b
·
verified ·
1 Parent(s): 9261cd9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load trained model
6
+ model = joblib.load("mental_wellness.pkl")
7
+
8
+ app = Flask(__name__)
9
+
10
+ @app.route("/", methods=["GET", "POST"])
11
+ def index():
12
+ prediction = None
13
+ if request.method == "POST":
14
+ try:
15
+ screen_time = float(request.form["screen_time"])
16
+ sleep_hours = float(request.form["sleep_hours"])
17
+ work_screen = float(request.form["work_screen"])
18
+
19
+ features = np.array([[screen_time, sleep_hours, work_screen]])
20
+ prediction = model.predict(features)[0]
21
+ prediction = round(prediction, 2)
22
+ except Exception as e:
23
+ prediction = f"Error: {str(e)}"
24
+
25
+ return render_template("index.html", prediction=prediction)
26
+
27
+ if __name__ == "__main__":
28
+ app.run(debug=True)