-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (50 loc) · 1.59 KB
/
app.py
File metadata and controls
60 lines (50 loc) · 1.59 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
from flask import Flask, render_template, request, redirect, send_file
import pandas as pd
import joblib
import os
from datetime import datetime
app = Flask(__name__)
# Load model and scaler
hybrid_model = joblib.load('hybrid_model.pkl')
scaler = joblib.load('scaler.pkl')
# Label mapping
label_map = {
1: "Standing still",
2: "Sitting and relaxing",
3: "Lying down",
4: "Walking",
5: "Climbing stairs",
6: "Waist bends forward",
7: "Frontal elevation of arms",
8: "Knees bending (crouching)",
9: "Cycling",
10: "Jogging",
11: "Running",
12: "Jump front & back"
}
@app.route('/', methods=['GET', 'POST'])
def index():
prediction_label = None
activity = None
filename = None
if request.method == 'POST':
file = request.files['file']
if file:
df = pd.read_csv(file)
filename = f"ecg_{datetime.today().strftime('%Y-%m-%d')}.csv"
df.to_csv(filename, index=False)
if 'label' in df.columns:
df = df.drop(columns=['label'])
df_scaled = scaler.transform(df)
prediction = hybrid_model.predict(df_scaled)
prediction_label = prediction[0]
activity = label_map.get(prediction_label, "Unknown")
return render_template('index.html', prediction_label=prediction_label,
activity=activity, filename=filename)
@app.route('/download/<filename>')
def download_file(filename):
return send_file(filename, as_attachment=True)
if __name__ == '__main__':
app.run(debug=True)
if __name__ == '__main__':
app.run()