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