File size: 929 Bytes
5f9624d
8e1f150
0918613
018537d
ba5672b
 
 
0918613
ba5672b
 
 
 
 
a3ed2ae
 
 
 
ba5672b
5f9624d
ba5672b
 
ff284fc
5f9624d
 
018537d
5f9624d
018537d
 
 
5f9624d
 
 
ba5672b
9c72f7a
ba5672b
 
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
from flask import Flask, send_from_directory, json, Response, request
from waitress import serve
from flask_cors import CORS, cross_origin
from model import SugoiTranslator


app = Flask(__name__)
CORS(app)

@app.route('/')
def index():
    return send_from_directory('dist', "index.html")

@app.route('/<path:filename>')
def download_file(filename):
    return send_from_directory('.', filename)

@app.route('/assets/<path:filename>')
def download_assets(filename):
    return send_from_directory('dist/assets', filename)

@app.route('/api/translate', methods= ['POST'])
@cross_origin()
def translate_api(): 
    input_text = request.args.get('text')
    sugoiTranslator = SugoiTranslator()
    if isinstance(input_text, str) and len(input_text) > 0: 
        text = sugoiTranslator.translate(input_text)
        return json.dumps(text)
    return Response(status= 400)


if __name__ == '__main__':
    serve(app, port= 7860)