yuripeyamashita
commited on
Commit
•
8b9c4e4
1
Parent(s):
5a85b96
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from flask import Flask, request
|
|
|
2 |
from uuid import uuid4
|
3 |
-
import os, json
|
4 |
-
import requests
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
@@ -20,51 +20,45 @@ def queue():
|
|
20 |
|
21 |
return { 'uuid': uuid }, 200
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
data = res_dict.get(uuid)
|
27 |
if not data:
|
28 |
return {}, 400
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
res = requests.post(URL, json=body, headers=headers)
|
34 |
if res.status_code == 200:
|
35 |
res_json = res.json()
|
36 |
-
|
37 |
callbackURL = data.get('callbackURL')
|
38 |
callback_body = data.get('callbackBody')
|
39 |
-
|
40 |
if res_json.get('data'):
|
41 |
callback_body['length'] = len(res_json['data'][0])
|
42 |
if res_json.get('srt'):
|
43 |
callback_body['srt'] = res_json['srt'][0]
|
44 |
-
|
45 |
requests.post(callbackURL, json=callback_body)
|
46 |
|
47 |
print(callback_body)
|
48 |
print(res_json)
|
49 |
-
|
50 |
return res_json
|
51 |
|
52 |
return {'error': '請求失敗'}, 500
|
53 |
|
54 |
|
55 |
-
# @app.route('/client', methods=['POST'])
|
56 |
-
# def client():
|
57 |
-
# token = request.json.get('token')
|
58 |
-
# data = reqList.get(token)
|
59 |
-
# if not data:
|
60 |
-
# return {}, 400
|
61 |
-
# print(data)
|
62 |
-
# URL = data.get('URL')
|
63 |
-
# postData = data.get('postData')
|
64 |
-
|
65 |
-
# response = requests.post(URL, json=postData)
|
66 |
-
|
67 |
-
# return response.json()
|
68 |
-
|
69 |
if __name__ == "__main__":
|
70 |
app.run(host="0.0.0.0", port=7860)
|
|
|
1 |
from flask import Flask, request
|
2 |
+
from gradio_client import Client
|
3 |
from uuid import uuid4
|
4 |
+
import os, json, requests, hashlib
|
|
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
|
|
20 |
|
21 |
return { 'uuid': uuid }, 200
|
22 |
|
23 |
+
|
24 |
+
@app.route('/6asr', methods=['POST'])
|
25 |
+
def sixasr():
|
26 |
+
data = res_dict.get(request.json.get('uuid'))
|
27 |
if not data:
|
28 |
return {}, 400
|
29 |
+
|
30 |
+
base64 = request.json.get('base64')
|
31 |
+
dialectCode = request.json.get('dialectCode')
|
32 |
+
if not base64 or not dialectCode:
|
33 |
+
return {}, 400
|
34 |
|
35 |
+
if hashlib.sha256(base64.encode('utf-8')).hexdigest() != data.get("hash"):
|
36 |
+
return {}, 400
|
37 |
+
|
38 |
+
URL = 'https://nuu-lab-gradio-6asr-whisper.hf.space/run/predict'
|
39 |
+
body = {'data': ["whisper-large-v3", f"htia_{dialectCode}", None, base64, '']}
|
40 |
+
|
41 |
res = requests.post(URL, json=body, headers=headers)
|
42 |
if res.status_code == 200:
|
43 |
res_json = res.json()
|
44 |
+
|
45 |
callbackURL = data.get('callbackURL')
|
46 |
callback_body = data.get('callbackBody')
|
47 |
+
|
48 |
if res_json.get('data'):
|
49 |
callback_body['length'] = len(res_json['data'][0])
|
50 |
if res_json.get('srt'):
|
51 |
callback_body['srt'] = res_json['srt'][0]
|
52 |
+
|
53 |
requests.post(callbackURL, json=callback_body)
|
54 |
|
55 |
print(callback_body)
|
56 |
print(res_json)
|
57 |
+
|
58 |
return res_json
|
59 |
|
60 |
return {'error': '請求失敗'}, 500
|
61 |
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
if __name__ == "__main__":
|
64 |
app.run(host="0.0.0.0", port=7860)
|