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)