Spaces:
Running
Running
clementruhm
commited on
Commit
·
5293275
1
Parent(s):
9079195
vc_service_request.py: use environ to access secrets
Browse files- requirements.txt +0 -1
- vc_service_request.py +4 -4
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
numpy==1.23.2
|
2 |
resampy==0.4.2
|
3 |
-
streamlit==1.22.0
|
4 |
websockets==10.3
|
|
|
1 |
numpy==1.23.2
|
2 |
resampy==0.4.2
|
|
|
3 |
websockets==10.3
|
vc_service_request.py
CHANGED
@@ -5,6 +5,7 @@ contains implementation
|
|
5 |
for voice conversion request
|
6 |
"""
|
7 |
|
|
|
8 |
import asyncio
|
9 |
import base64
|
10 |
import hashlib
|
@@ -15,7 +16,6 @@ from typing import Tuple
|
|
15 |
|
16 |
import numpy as np
|
17 |
import resampy
|
18 |
-
import streamlit as st
|
19 |
import websockets
|
20 |
|
21 |
|
@@ -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 = (
|
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 |
-
|
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":
|
65 |
"signature": create_signature(),
|
66 |
}
|
67 |
request = json.dumps(request_dict)
|
|
|
5 |
for voice conversion request
|
6 |
"""
|
7 |
|
8 |
+
import os
|
9 |
import asyncio
|
10 |
import base64
|
11 |
import hashlib
|
|
|
16 |
|
17 |
import numpy as np
|
18 |
import resampy
|
|
|
19 |
import websockets
|
20 |
|
21 |
|
|
|
47 |
required to authentificate the request
|
48 |
"""
|
49 |
int_time = int(time.time() / 1000)
|
50 |
+
signature_input = (os.environ["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 |
+
os.environ["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": os.environ["api_key"],
|
65 |
"signature": create_signature(),
|
66 |
}
|
67 |
request = json.dumps(request_dict)
|