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.2 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
  1. from flask import Flask, request, jsonify, render_template
  2. import os
  3. from flask_cors import CORS, cross_origin
  4. from kidneyDiseaseClassifier.utils.common import decodeImage
  5. from kidneyDiseaseClassifier.pipeline.stage_05_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) -> None:
  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 train():
  21. os.system("dvc repro")
  22. # os.system("python main.py")
  23. return "Training completed successfully."
  24. @app.route("/predict", methods=["POST"])
  25. @cross_origin()
  26. def predict():
  27. image = request.json['image']
  28. decodeImage(image, clientApp.filename)
  29. result = clientApp.classifier.predict()
  30. return jsonify(result)
  31. if __name__ == "__main__":
  32. clientApp = ClientApp()
  33. # app.run(host="0.0.0.0", port=80) for Microsoft Azure
  34. app.run(host="0.0.0.0", port=5000) # Amazon Web Services and localhost
Tip!

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

Comments

Loading...