PyDeepL-test / app.py
IHaBiS's picture
Update app.py
a20e34a verified
raw
history blame contribute delete
868 Bytes
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)