File size: 1,242 Bytes
9fdad88
4a9c2e6
 
 
9fdad88
4a9c2e6
 
9fdad88
4a9c2e6
9fdad88
 
 
 
 
 
 
9597931
4a9c2e6
 
9597931
 
4a9c2e6
 
 
9fdad88
9597931
 
 
 
 
 
 
 
9fdad88
 
 
9597931
4a9c2e6
 
8d648d2
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
import logging
from flask import Flask, render_template, request
import pickle

logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)

app.logger.debug("Starting Flask app initialization.")

# Load the model
try:
    with open("random_forest_model.pkl", "rb") as file:
        model = pickle.load(file)
    app.logger.debug("Model loaded successfully.")
except Exception as e:
    app.logger.error(f"Error loading model: {e}")

@app.route('/')
def index():
    app.logger.info("Accessed '/' route.")
    return render_template('index.html')

@app.route('/predict', methods=['POST'])
def predict():
    app.logger.debug("Predict route accessed.")
    try:
        precipitation = float(request.form['precipitation'])
        temp_max = float(request.form['temp_max'])
        temp_min = float(request.form['temp_min'])
        wind = float(request.form['wind'])
        prediction = model.predict([[precipitation, temp_max, temp_min, wind]])
        return render_template('result.html', prediction=prediction[0])
    except Exception as e:
        app.logger.error(f"Error in predict route: {e}")
        return "An error occurred during prediction."



if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860, debug=False)