IHaBiS commited on
Commit
ce75c13
โ€ข
1 Parent(s): cbe60a0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
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)