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.8 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
  1. import traceback
  2. from datetime import datetime
  3. from flask import Flask, render_template, request
  4. import os
  5. import numpy as np
  6. import pandas as pd
  7. from mlProject.pipeline.prediction import PredictionPipeline
  8. app = Flask(__name__) # initializing a flask app
  9. @app.route('/', methods=['GET']) # route to display the home page
  10. def homePage():
  11. return render_template("index.html")
  12. @app.route('/train', methods=['GET']) # route to train the pipeline
  13. def training():
  14. os.system("python main.py")
  15. return "Training Successful!"
  16. @app.route('/predict', methods=['POST', 'GET']) # route to show the predictions in a web UI
  17. def index():
  18. if request.method == 'POST':
  19. try:
  20. # reading the inputs given by the user
  21. Clock = datetime.strptime(request.form['Clock'], '%Y-%m-%d')
  22. sensor = str(request.form['sensor'])
  23. R_Voltage = float(request.form['R_Voltage'])
  24. Y_Voltage = float(request.form['Y_Voltage'])
  25. B_Voltage = float(request.form['B_Voltage'])
  26. R_Current = float(request.form['R_Current'])
  27. Y_Current = float(request.form['Y_Current'])
  28. B_Current = float(request.form['B_Current'])
  29. data = [Clock, sensor, R_Voltage, Y_Voltage, B_Voltage, R_Current, Y_Current, B_Current]
  30. data = np.array(data).reshape(1, 11)
  31. obj = PredictionPipeline()
  32. predict = obj.predict(data)
  33. return render_template('results.html', prediction=str(predict))
  34. except Exception as e:
  35. print(traceback.format_exc())
  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...