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.0 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
  1. from flask import Flask, render_template, request
  2. import os
  3. import numpy as np
  4. import pandas as pd
  5. from src.mlProject.pipeline.prediction import PredictionPipeline
  6. app = Flask(__name__) # initializing a flask app
  7. @app.route('/',methods=['GET']) # route to display the home page
  8. def homePage():
  9. return render_template("index.html")
  10. @app.route('/train',methods=['GET']) # route to train the pipeline
  11. def training():
  12. os.system("python main.py")
  13. return "Training Successful!"
  14. @app.route('/predict',methods=['POST','GET']) # route to show the predictions in a web UI
  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. data = [fixed_acidity,volatile_acidity,citric_acid,residual_sugar,chlorides,free_sulfur_dioxide,total_sulfur_dioxide,density,pH,sulphates,alcohol]
  31. data = np.array(data).reshape(1, 11)
  32. obj = PredictionPipeline()
  33. predict = obj.predict(data)
  34. return render_template('results.html', prediction = str(predict))
  35. except Exception as e:
  36. print('The Exception message is: ',e)
  37. return 'something is wrong'
  38. else:
  39. return render_template('index.html')
  40. if __name__ == "__main__":
  41. # app.run(host="0.0.0.0", port = 8080, debug=True)
  42. app.run(host="0.0.0.0", port = 8080)
Tip!

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

Comments

Loading...