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.1 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
  1. from flask import Flask, request, jsonify, render_template
  2. import os
  3. from flask_cors import CORS, cross_origin
  4. from cnnClassifier.utils.common import decodeImage
  5. from cnnClassifier.pipeline.prediction import PredictionPipeline
  6. os.putenv('LANG', 'en_US.UTF-8')
  7. os.putenv('LC_ALL', 'en_US.UTF-8')
  8. app = Flask(__name__)
  9. CORS(app)
  10. class ClientApp:
  11. def __init__(self):
  12. self.filename = "inputImage.jpg"
  13. self.classifier = PredictionPipeline(self.filename)
  14. @app.route("/", methods=['GET'])
  15. @cross_origin()
  16. def home():
  17. return render_template('index.html')
  18. @app.route("/train", methods=['GET','POST'])
  19. @cross_origin()
  20. def trainRoute():
  21. # os.system("python main.py")
  22. os.system("dvc repro")
  23. return "Training done successfully!"
  24. @app.route("/predict", methods=['POST'])
  25. @cross_origin()
  26. def predictRoute():
  27. image = request.json['image']
  28. decodeImage(image, clApp.filename)
  29. result = clApp.classifier.predict()
  30. return jsonify(result)
  31. if __name__ == "__main__":
  32. clApp = ClientApp()
  33. app.run(host='0.0.0.0', port=8080) #for AWS
Tip!

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

Comments

Loading...