forked from lithin-minfy/Risk_Classification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp1.py
More file actions
40 lines (30 loc) · 1.03 KB
/
app1.py
File metadata and controls
40 lines (30 loc) · 1.03 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
from flask import Flask, request, render_template
import pandas as pd
import joblib
import os
app = Flask(__name__)
# Load trained pipeline
pipeline_path = 'trained_pipeline.pkl'
if not os.path.exists(pipeline_path):
raise FileNotFoundError(f"🚫 Pipeline file not found: {pipeline_path}")
model = joblib.load(pipeline_path)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/success', methods=['POST'])
def success():
if 'file' not in request.files:
return "❌ No file uploaded."
file = request.files['file']
if file.filename == '':
return "❌ No file selected."
try:
# Load uploaded CSV
df = pd.read_csv(file)
# ✅ Directly use trained pipeline (includes preprocessing)
df['Prediction'] = model.predict(df)
return render_template("data.html", Y=df.to_html(classes='table', index=False))
except Exception as e:
return f"⚠️ Error while processing file: {str(e)}"
if __name__ == '__main__':
app.run(debug=True)