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.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
  1. from flask import Flask, request, jsonify, render_template
  2. import os, sys
  3. from flask_cors import CORS, cross_origin
  4. from cnnClassifier.utils.common import decodeImage
  5. from cnnClassifier.pipeline.predict 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. return "Training done successfully!"
  23. @app.route("/predict", methods=['POST'])
  24. @cross_origin()
  25. def predictRoute():
  26. image = request.json['image']
  27. decodeImage(image, clApp.filename)
  28. result = clApp.classifier.predict()
  29. return jsonify(result)
  30. if __name__ == '__main__':
  31. clApp = ClientApp()
  32. 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...