Spaces:
Running
Running
clementruhm
commited on
Commit
•
9079195
1
Parent(s):
802e11f
vc_service_request.py: fix st usage, dont process requests that are way too long
Browse files- vc_service_request.py +6 -3
vc_service_request.py
CHANGED
@@ -47,7 +47,7 @@ def create_signature(api_secret: str) -> str:
|
|
47 |
required to authentificate the request
|
48 |
"""
|
49 |
int_time = int(time.time() / 1000)
|
50 |
-
signature_input = (st["api_secret"] + str(int_time)).encode()
|
51 |
signature = hashlib.sha256(signature_input).hexdigest()
|
52 |
return signature
|
53 |
|
@@ -56,12 +56,12 @@ async def async_service_request(source: np.ndarray, target: np.ndarray) -> np.nd
|
|
56 |
ssl_context = ssl.create_default_context()
|
57 |
|
58 |
async with websockets.connect(
|
59 |
-
st["endpoint"], close_timeout=1024, ssl=ssl_context
|
60 |
) as websocket:
|
61 |
request_dict = {
|
62 |
"source": base64.b64encode(source.tobytes()).decode("utf-8"),
|
63 |
"target": base64.b64encode(target.tobytes()).decode("utf-8"),
|
64 |
-
"api_key": st["api_key"],
|
65 |
"signature": create_signature(),
|
66 |
}
|
67 |
request = json.dumps(request_dict)
|
@@ -90,6 +90,9 @@ def vc_service_request(
|
|
90 |
"""
|
91 |
src = prepare_audio(source_audio)
|
92 |
tgt = prepare_audio(target_audio)
|
|
|
|
|
|
|
93 |
|
94 |
res = asyncio.run(async_service_request(src, tgt))
|
95 |
return 16000, res
|
|
|
47 |
required to authentificate the request
|
48 |
"""
|
49 |
int_time = int(time.time() / 1000)
|
50 |
+
signature_input = (st.secrets["api_secret"] + str(int_time)).encode()
|
51 |
signature = hashlib.sha256(signature_input).hexdigest()
|
52 |
return signature
|
53 |
|
|
|
56 |
ssl_context = ssl.create_default_context()
|
57 |
|
58 |
async with websockets.connect(
|
59 |
+
st.secrets["endpoint"], close_timeout=1024, ssl=ssl_context
|
60 |
) as websocket:
|
61 |
request_dict = {
|
62 |
"source": base64.b64encode(source.tobytes()).decode("utf-8"),
|
63 |
"target": base64.b64encode(target.tobytes()).decode("utf-8"),
|
64 |
+
"api_key": st.secrets["api_key"],
|
65 |
"signature": create_signature(),
|
66 |
}
|
67 |
request = json.dumps(request_dict)
|
|
|
90 |
"""
|
91 |
src = prepare_audio(source_audio)
|
92 |
tgt = prepare_audio(target_audio)
|
93 |
+
if len(src) >= 60 * 16000 or len(tgt) >= 30 * 16000:
|
94 |
+
# input is way too long, dont return anything
|
95 |
+
return
|
96 |
|
97 |
res = asyncio.run(async_service_request(src, tgt))
|
98 |
return 16000, res
|