-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (46 loc) · 1.59 KB
/
app.py
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
from flask import Flask, request, render_template
from model import WeatherPrediction
app = Flask(__name__)
WP = WeatherPrediction(data_path='weather.csv')
WP.run()
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
try:
# Retrieve and convert form data
temperature = float(request.form['temperature'])
humidity = float(request.form['humidity'])
wind_speed = float(request.form['wind_speed'])
precipitation = float(request.form['precipitation'])
atmospheric_pressure = float(request.form['atmospheric_pressure'])
uv_index = float(request.form['uv_index'])
visibility = float(request.form['visibility'])
# Make prediction
prediction = WP.predict(
temperature,
humidity,
wind_speed,
precipitation,
atmospheric_pressure,
uv_index,
visibility
)
# Render the result page
return render_template(
'result.html',
temperature=temperature,
humidity=humidity,
wind_speed=wind_speed,
precipitation=precipitation,
atmospheric_pressure=atmospheric_pressure,
uv_index=uv_index,
visibility=visibility,
result=prediction
)
except (KeyError, ValueError) as e:
# Handle missing or invalid form data
return f"Error processing your request: {e}", 400
if __name__ == '__main__':
app.run(debug=False, port=8000)