Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

server.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
  1. import traceback
  2. from flask import Flask, request, send_from_directory, render_template
  3. from python.style_predict import autotag, load_model
  4. app = Flask(__name__)
  5. model, params = load_model('model')
  6. @app.route('/assets/<path:path>')
  7. def serve_assets(path):
  8. return send_from_directory('assets', path)
  9. @app.route('/favicon.ico')
  10. def favicon():
  11. return send_from_directory('assets', 'favicon.ico')
  12. @app.after_request
  13. def add_no_cache(response):
  14. if request.endpoint != "static":
  15. response.headers["Cache-Control"] = "no-cache"
  16. response.headers["Pragma"] = "no-cache"
  17. return response
  18. @app.errorhandler(404)
  19. def page_not_found(e):
  20. return render_template('404.html')
  21. @app.route('/style', methods=["GET", "POST"])
  22. def style():
  23. try:
  24. txt = request.form["txt"]
  25. return autotag(txt, model, params)
  26. except Exception as e:
  27. return "<h2>"+str(e)+"</h2>" + traceback.format_exc().replace('\n', '<br>')
  28. @app.route('/')
  29. def root():
  30. return render_template('index.html')
  31. if __name__ == "__main__":
  32. app.run(host='0.0.0.0', debug=True)
Tip!

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

Comments

Loading...