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 1.9 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
  1. from flask import Flask, render_template, request
  2. import numpy as np
  3. from mlProject.pipeline.prediction import PredictionPipeline
  4. app = Flask(__name__)
  5. # Global constant for state dictionary
  6. STATE_DICTIONARY = {'AL': 0, 'AR': 1, 'AZ': 2, 'CA': 3, 'CO': 4, 'FL': 5, 'GA': 6, 'HI': 7, 'IA': 8, 'ID': 9, 'IL': 10, 'IN': 11,
  7. 'KS': 12, 'KY': 13, 'LA': 14, 'MD': 15, 'ME': 16, 'MI': 17, 'MN': 18, 'MO': 19, 'MS': 20, 'MT': 21, 'NC': 22,
  8. 'ND': 23, 'NE': 24, 'NJ': 25, 'NM': 26, 'NV': 27, 'NY': 28, 'OH': 29, 'OK': 30, 'OR': 31, 'PA': 32, 'SC': 33,
  9. 'SD': 34, 'TN': 35, 'TX': 36, 'UT': 37, 'VA': 38, 'VT': 39, 'WA': 40, 'WI': 41, 'WV': 42, 'WY': 43}
  10. @app.route('/', methods=['GET'])
  11. def home_page():
  12. return render_template("index.html")
  13. @app.route("/predict", methods=['POST','GET'])
  14. def index():
  15. if request.method == "POST":
  16. try:
  17. state = request.form['state']
  18. state= STATE_DICTIONARY[state]
  19. num_col = float(request.form['numcol'])
  20. yield_per_col = int(request.form['yieldpercol'])
  21. total_prod = float(request.form['totalprod'])
  22. stocks = float(request.form['stocks'])
  23. prod_value = float(request.form['prodvalue'])
  24. year = int(request.form['year'])
  25. except Exception as e:
  26. print('The Exception message is:', e)
  27. return 'Something went wrong'
  28. else:
  29. return render_template("index.html")
  30. data = [state, num_col, yield_per_col, total_prod, stocks, prod_value, year]
  31. data = np.array(data).reshape(1, 7)
  32. obj = PredictionPipeline()
  33. predict = obj.predict(data)[0]
  34. return render_template('index.html', prediction = f' Honey price per pound is ${round(predict,2)}')
  35. if __name__ == "__main__":
  36. # app.run(host="0.0.0.0", port=8080, debug=True)
  37. app.run(debug=True)
Tip!

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

Comments

Loading...