Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, Response
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import datetime
|
5 |
+
import os
|
6 |
+
from PyDeepLX import PyDeepLX
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
@app.route('/translate', methods=['POST'])
|
11 |
+
def proxy():
|
12 |
+
# ์ธ๋ถ์์ ๋ค์ด์จ POST ์์ฒญ์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
13 |
+
request_data = request.get_data()
|
14 |
+
access_token = request.headers.get('Authorization')
|
15 |
+
if access_token != f'Bearer {os.environ["ACCESS_TOKEN"]}':
|
16 |
+
return Response(status=401)
|
17 |
+
else:
|
18 |
+
translated_sentence = PyDeepLX.translate(request_data["text"], request_data["source_lang"], request_data["target_lang"])
|
19 |
+
temp_res = {"alternatives": [], "code": 200, "data": translated_sentence, "source_lang": request_data["source_lang"], "target_lang": request_data["target_lang"]}
|
20 |
+
return jsonify(temp_res)
|
21 |
+
if __name__ == '__main__':
|
22 |
+
app.run(port=7860)
|