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
  1. from flask import Flask, render_template, request, jsonify
  2. import os
  3. import numpy as np
  4. from prediction_service import prediction
  5. webapp_root = "webapp"
  6. static_dir = os.path.join(webapp_root, "static")
  7. template_dir = os.path.join(webapp_root, "templates")
  8. app = Flask(__name__, static_folder=static_dir,template_folder=template_dir)
  9. @app.route("/", methods=["GET", "POST"])
  10. def index():
  11. if request.method == "POST":
  12. try:
  13. if request.form:
  14. dict_req = dict(request.form)
  15. response = prediction.form_response(dict_req)
  16. return render_template("index.html", response=response)
  17. elif request.json:
  18. response = prediction.api_response(request.json)
  19. return jsonify(response)
  20. except Exception as e:
  21. print(e)
  22. error = {"error": "Something went wrong!! Try again later!"}
  23. error = {"error": e}
  24. return render_template("404.html", error=error)
  25. else:
  26. return render_template("index.html")
  27. if __name__ == "__main__":
  28. app.run(host='0.0.0.0', port=5000, debug=True)
Tip!

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

Comments

Loading...