raphaelbiojout
commited on
Commit
·
7c6c8d7
1
Parent(s):
a60c8b9
correction
Browse files- call.py +29 -0
- create_handler.ipynb +0 -0
- handler.py +11 -2
call.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import base64
|
3 |
+
import json
|
4 |
+
|
5 |
+
API_URL = "https://w4a3d6hyuuiyrznb.eu-west-1.aws.endpoints.huggingface.cloud"
|
6 |
+
headers = {
|
7 |
+
"Authorization": "Bearer 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",
|
8 |
+
"Content-Type": "application/json"
|
9 |
+
}
|
10 |
+
|
11 |
+
def query(filename):
|
12 |
+
with open(filename, "rb") as f:
|
13 |
+
audio_data = f.read()
|
14 |
+
print(audio_data)
|
15 |
+
# Encode the audio data as base64
|
16 |
+
audio_base64 = base64.b64encode(audio_data).decode("utf-8")
|
17 |
+
# print(audio_base64)
|
18 |
+
|
19 |
+
# Construct the JSON payload
|
20 |
+
payload = {
|
21 |
+
"inputs": audio_data,
|
22 |
+
}
|
23 |
+
|
24 |
+
response = requests.post(API_URL, headers=headers, data=payload)
|
25 |
+
return response.json()
|
26 |
+
|
27 |
+
output = query("sample1.flac")
|
28 |
+
print("-----------------")
|
29 |
+
print(output)
|
create_handler.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
handler.py
CHANGED
@@ -126,7 +126,7 @@ class EndpointHandler():
|
|
126 |
logger.info(f"Model for diarization initialized")
|
127 |
|
128 |
|
129 |
-
def __call__(self, data:
|
130 |
"""
|
131 |
Args:
|
132 |
data (:obj:):
|
@@ -141,7 +141,16 @@ class EndpointHandler():
|
|
141 |
print(f"key: {x}, value: {data[x]} ")
|
142 |
|
143 |
# 1. process input
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
inputs = base64.b64decode(inputs_encoded)
|
146 |
|
147 |
print(inputs)
|
|
|
126 |
logger.info(f"Model for diarization initialized")
|
127 |
|
128 |
|
129 |
+
def __call__(self, data: Any) -> Dict[str, str]:
|
130 |
"""
|
131 |
Args:
|
132 |
data (:obj:):
|
|
|
141 |
print(f"key: {x}, value: {data[x]} ")
|
142 |
|
143 |
# 1. process input
|
144 |
+
inputs = data.pop("inputs", data)
|
145 |
+
parameters = data.pop("parameters", None)
|
146 |
+
|
147 |
+
inputs_encoded = inputs["audio_encoded"]
|
148 |
+
print(inputs_encoded)
|
149 |
+
|
150 |
+
language = None
|
151 |
+
if "language" in inputs.keys():
|
152 |
+
language = inputs["language"]
|
153 |
+
|
154 |
inputs = base64.b64decode(inputs_encoded)
|
155 |
|
156 |
print(inputs)
|