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