feat: add route to the model
Browse files- server/app.py +12 -2
server/app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
-
from flask import Flask, send_from_directory
|
2 |
from waitress import serve
|
3 |
from flask_cors import CORS, cross_origin
|
|
|
4 |
|
5 |
|
6 |
app = Flask(__name__)
|
@@ -15,9 +16,18 @@ def download_file(filename):
|
|
15 |
return send_from_directory('.', filename)
|
16 |
|
17 |
@app.route('/assets/<path:filename>')
|
18 |
-
def
|
19 |
return send_from_directory('dist/assets', filename)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
if __name__ == '__main__':
|
22 |
serve(app)
|
23 |
|
|
|
1 |
+
from flask import Flask, send_from_directory, json, Response, request
|
2 |
from waitress import serve
|
3 |
from flask_cors import CORS, cross_origin
|
4 |
+
from server.model import SugoiTranslator
|
5 |
|
6 |
|
7 |
app = Flask(__name__)
|
|
|
16 |
return send_from_directory('.', filename)
|
17 |
|
18 |
@app.route('/assets/<path:filename>')
|
19 |
+
def download_assets(filename):
|
20 |
return send_from_directory('dist/assets', filename)
|
21 |
|
22 |
+
@app.route('api/translate', methods= ['POST'])
|
23 |
+
@cross_origin()
|
24 |
+
def translate_api():
|
25 |
+
text = request.args.get('text')
|
26 |
+
sugoiTranslator = SugoiTranslator()
|
27 |
+
if isinstance(text, str) and len(text) > 0: return json.dump(sugoiTranslator.translate(text))
|
28 |
+
return Response(status= 400)
|
29 |
+
|
30 |
+
|
31 |
if __name__ == '__main__':
|
32 |
serve(app)
|
33 |
|