Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 2.6 KB

You have to be logged in to leave a comment. Sign In
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  1. from flask import Flask,render_template,url_for,request,jsonify
  2. from flask_cors import cross_origin
  3. import pandas as pd
  4. import numpy as np
  5. import datetime
  6. import pickle
  7. app = Flask(__name__, template_folder="template")
  8. model = pickle.load(open("./models/cat.pkl", "rb"))
  9. print("Model Loaded")
  10. @app.route("/",methods=['GET'])
  11. @cross_origin()
  12. def home():
  13. return render_template("index.html")
  14. @app.route("/predict",methods=['GET', 'POST'])
  15. @cross_origin()
  16. def predict():
  17. if request.method == "POST":
  18. # DATE
  19. date = request.form['date']
  20. day = float(pd.to_datetime(date, format="%Y-%m-%dT").day)
  21. month = float(pd.to_datetime(date, format="%Y-%m-%dT").month)
  22. # MinTemp
  23. minTemp = float(request.form['mintemp'])
  24. # MaxTemp
  25. maxTemp = float(request.form['maxtemp'])
  26. # Rainfall
  27. rainfall = float(request.form['rainfall'])
  28. # Evaporation
  29. evaporation = float(request.form['evaporation'])
  30. # Sunshine
  31. sunshine = float(request.form['sunshine'])
  32. # Wind Gust Speed
  33. windGustSpeed = float(request.form['windgustspeed'])
  34. # Wind Speed 9am
  35. windSpeed9am = float(request.form['windspeed9am'])
  36. # Wind Speed 3pm
  37. windSpeed3pm = float(request.form['windspeed3pm'])
  38. # Humidity 9am
  39. humidity9am = float(request.form['humidity9am'])
  40. # Humidity 3pm
  41. humidity3pm = float(request.form['humidity3pm'])
  42. # Pressure 9am
  43. pressure9am = float(request.form['pressure9am'])
  44. # Pressure 3pm
  45. pressure3pm = float(request.form['pressure3pm'])
  46. # Temperature 9am
  47. temp9am = float(request.form['temp9am'])
  48. # Temperature 3pm
  49. temp3pm = float(request.form['temp3pm'])
  50. # Cloud 9am
  51. cloud9am = float(request.form['cloud9am'])
  52. # Cloud 3pm
  53. cloud3pm = float(request.form['cloud3pm'])
  54. # Cloud 3pm
  55. location = float(request.form['location'])
  56. # Wind Dir 9am
  57. winddDir9am = float(request.form['winddir9am'])
  58. # Wind Dir 3pm
  59. winddDir3pm = float(request.form['winddir3pm'])
  60. # Wind Gust Dir
  61. windGustDir = float(request.form['windgustdir'])
  62. # Rain Today
  63. rainToday = float(request.form['raintoday'])
  64. input_lst = [location , minTemp , maxTemp , rainfall , evaporation , sunshine ,
  65. windGustDir , windGustSpeed , winddDir9am , winddDir3pm , windSpeed9am , windSpeed3pm ,
  66. humidity9am , humidity3pm , pressure9am , pressure3pm , cloud9am , cloud3pm , temp9am , temp3pm ,
  67. rainToday , month , day]
  68. pred = model.predict(input_lst)
  69. output = pred
  70. if output == 0:
  71. return render_template("after_sunny.html")
  72. else:
  73. return render_template("after_rainy.html")
  74. return render_template("predictor.html")
  75. if __name__=='__main__':
  76. app.run(debug=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...