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
  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. #print(hello)
  9. app = Flask(__name__)
  10. CORS(app)
  11. class ClientApp:
  12. def __init__(self):
  13. self.filename = "inputImage.jpg"
  14. self.classifier = PredictionPipeline(self.filename)
  15. @app.route("/", methods=['GET'])
  16. @cross_origin()
  17. def home():
  18. return render_template('index.html')
  19. @app.route("/train", methods=['GET','POST'])
  20. @cross_origin()
  21. def trainRoute():
  22. os.system("python main.py")
  23. # os.system("dvc repro")
  24. return "Training done successfully!"
  25. @app.route("/predict", methods=['POST'])
  26. @cross_origin()
  27. def predictRoute():
  28. image = request.json['image']
  29. decodeImage(image, clApp.filename)
  30. result = clApp.classifier.predict()
  31. return jsonify(result)
  32. if __name__ == "__main__":
  33. clApp = ClientApp()
  34. 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...