-
Notifications
You must be signed in to change notification settings - Fork 2
/
flask-app.py
77 lines (64 loc) · 2.09 KB
/
flask-app.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#보안에 상당히 취약하다. 수정예정
from flask import Flask, request, jsonify
from flask_cors import CORS
import subprocess
import shlex
app = Flask(__name__)
CORS(app)
@app.route('/tts')
def run_tts():
tts = request.args.get('tts', default='')
ttsid = request.args.get('ttsid', default='')
uid = request.args.get('uid', default='')
vid = request.args.get('vid', default='')
pitch = request.args.get('pitch', default='')
script_path = '../tts_all.py'
command = f'python {script_path} --tts "{tts}" --ttsid {ttsid} --uid {uid} --vid {vid} --pitch {pitch}'
args = shlex.split(command)
try:
result = subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
response = {
'status': 'success',
'output': result.stdout,
'exit_code': 0
}
except subprocess.CalledProcessError as e:
response = {
'status': 'error',
'error': e.stderr,
'exit_code': 1
}
return jsonify(response)
@app.route('/merge')
def run_merge():
uid1 = request.args.get('uid1', default='')
vid1 = request.args.get('vid1', default='')
vid2 = request.args.get('vid2', default='')
vid3 = request.args.get('vid3', default='')
script_path = '../merge.py'
command = f'python {script_path} {uid1} {vid1} {vid2} {vid3}'
args = shlex.split(command)
try:
result = subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
response = {
'status': 'success',
'output': result.stdout,
'exit_code': 0
}
except subprocess.CalledProcessError as e:
response = {
'status': 'error',
'error': e.stderr,
'exit_code': 1
}
return jsonify(response)
@app.route('/train')
def run_train():
response = {
'status': 'error',
'error': 'Cannot use GPU in this VM',
'exit_code': 1
}
return jsonify(response)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)