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
51
52
  1. from flask import Flask, render_template, request
  2. import os
  3. import numpy as np
  4. import pandas as pd
  5. from mlProject.pipeline.prediction import PredictionPipeline
  6. app = Flask(__name__) # create an instance of the Flask class
  7. @app.route('/', methods=['GET'])
  8. def homepage():
  9. return render_template('index.html')
  10. @app.route('/train', methods=['GET'])
  11. def train():
  12. os.system("python main.py")
  13. return "Training is completed!"
  14. @app.route('/predict', methods=['POST', 'GET'])
  15. def index():
  16. if request.method == 'POST':
  17. try:
  18. # reading the inputs given by the user
  19. fixed_acidity = float(request.form['fixed_acidity'])
  20. volatile_acidity = float(request.form['volatile_acidity'])
  21. citric_acid = float(request.form['citric_acid'])
  22. residual_sugar = float(request.form['residual_sugar'])
  23. chlorides = float(request.form['chlorides'])
  24. free_sulfur_dioxide = float(request.form['free_sulfur_dioxide'])
  25. total_sulfur_dioxide = float(request.form['total_sulfur_dioxide'])
  26. density = float(request.form['density'])
  27. pH = float(request.form['pH'])
  28. sulphates = float(request.form['sulphates'])
  29. alcohol = float(request.form['alcohol'])
  30. #
  31. data = [fixed_acidity, volatile_acidity, citric_acid, residual_sugar, chlorides, free_sulfur_dioxide, total_sulfur_dioxide, density, pH, sulphates, alcohol]
  32. data = np.array(data).reshape(1, 11)
  33. obj = PredictionPipeline()
  34. predict = obj.predict(data)
  35. return render_template('results.html', prediction=str(predict))
  36. except Exception as e:
  37. print('The exception message is: ', e)
  38. return 'Something is wrong!'
  39. else:
  40. return render_template('index.html')
  41. if __name__ == '__main__':
  42. app.run(host='0.0.0.0', port=8080, debug=True)
Tip!

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

Comments

Loading...