File size: 868 Bytes
a20e34a
ce75c13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from flask import Flask, request, Response, jsonify
import requests
import json
import datetime
import os
from PyDeepLX import PyDeepLX

app = Flask(__name__)

@app.route('/translate', methods=['POST'])
def proxy():
    # 외부에서 들어온 POST 요청의 데이터 가져오기
    request_data = request.get_data()
    access_token = request.headers.get('Authorization')
    if access_token != f'Bearer {os.environ["ACCESS_TOKEN"]}':
        return Response(status=401)
    else:
        translated_sentence = PyDeepLX.translate(request_data["text"], request_data["source_lang"], request_data["target_lang"])
        temp_res = {"alternatives": [], "code": 200, "data": translated_sentence, "source_lang": request_data["source_lang"], "target_lang": request_data["target_lang"]}
        return jsonify(temp_res)
if __name__ == '__main__':
    app.run(port=7860)