Spaces:
Running
Running
clementruhm
commited on
Commit
•
1124846
1
Parent(s):
d192051
Update service_request.py
Browse files- service_request.py +6 -2
service_request.py
CHANGED
@@ -63,6 +63,10 @@ def create_signature(api_secret: str) -> str:
|
|
63 |
|
64 |
|
65 |
async def async_service_request(source_str: str, source: np.ndarray, target: np.ndarray, api_key: str, api_secret: str) -> np.ndarray:
|
|
|
|
|
|
|
|
|
66 |
ssl_context = ssl.create_default_context()
|
67 |
|
68 |
async with websockets.connect(
|
@@ -73,9 +77,9 @@ async def async_service_request(source_str: str, source: np.ndarray, target: np.
|
|
73 |
"api_key": api_key,
|
74 |
"signature": create_signature(api_secret),
|
75 |
}
|
76 |
-
if source_str
|
77 |
request_dict["source_str"] = source_str
|
78 |
-
elif source
|
79 |
request_dict["source"] = base64.b64encode(source.tobytes()).decode("utf-8")
|
80 |
else:
|
81 |
return None
|
|
|
63 |
|
64 |
|
65 |
async def async_service_request(source_str: str, source: np.ndarray, target: np.ndarray, api_key: str, api_secret: str) -> np.ndarray:
|
66 |
+
|
67 |
+
if not target or len(target) == 0:
|
68 |
+
return None
|
69 |
+
|
70 |
ssl_context = ssl.create_default_context()
|
71 |
|
72 |
async with websockets.connect(
|
|
|
77 |
"api_key": api_key,
|
78 |
"signature": create_signature(api_secret),
|
79 |
}
|
80 |
+
if source_str and len(source_str) > 0:
|
81 |
request_dict["source_str"] = source_str
|
82 |
+
elif source and len(source) > 0:
|
83 |
request_dict["source"] = base64.b64encode(source.tobytes()).decode("utf-8")
|
84 |
else:
|
85 |
return None
|