Commit
·
7e06129
1
Parent(s):
a295a8d
proper base64 encoding
Browse files- __pycache__/handler.cpython-39.pyc +0 -0
- handler.py +4 -2
- test_handler.py +4 -1
__pycache__/handler.cpython-39.pyc
ADDED
|
Binary file (1.76 kB). View file
|
|
|
handler.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
| 2 |
from typing import Dict, Any, List
|
| 3 |
from transformers import pipeline
|
| 4 |
import torch
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
class EndpointHandler:
|
|
@@ -32,7 +34,7 @@ class EndpointHandler:
|
|
| 32 |
List[Dict[str, Any]]: _description_
|
| 33 |
"""
|
| 34 |
inputs = data["inputs"]
|
| 35 |
-
audio = inputs["audio"] # bytes
|
| 36 |
lang = inputs["language"]
|
| 37 |
task = inputs["task"] # One of "translate", "transcribe"
|
| 38 |
|
|
@@ -41,6 +43,6 @@ class EndpointHandler:
|
|
| 41 |
self.pipeline
|
| 42 |
|
| 43 |
# Model inference
|
| 44 |
-
output = self.pipeline(audio
|
| 45 |
|
| 46 |
return output
|
|
|
|
| 2 |
from typing import Dict, Any, List
|
| 3 |
from transformers import pipeline
|
| 4 |
import torch
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
import base64
|
| 7 |
|
| 8 |
|
| 9 |
class EndpointHandler:
|
|
|
|
| 34 |
List[Dict[str, Any]]: _description_
|
| 35 |
"""
|
| 36 |
inputs = data["inputs"]
|
| 37 |
+
audio = base64.b64decode(inputs["audio"]) # bytes
|
| 38 |
lang = inputs["language"]
|
| 39 |
task = inputs["task"] # One of "translate", "transcribe"
|
| 40 |
|
|
|
|
| 43 |
self.pipeline
|
| 44 |
|
| 45 |
# Model inference
|
| 46 |
+
output = self.pipeline(audio, return_timestamps="word")
|
| 47 |
|
| 48 |
return output
|
test_handler.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
"""Test the custom handler."""
|
| 2 |
from handler import EndpointHandler
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
handler = EndpointHandler(path="whisper-tiny")
|
| 6 |
|
| 7 |
with open("frank.wav", "rb") as file:
|
| 8 |
audio = file.read()
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
output = handler(payload)
|
| 13 |
|
|
|
|
| 1 |
"""Test the custom handler."""
|
| 2 |
from handler import EndpointHandler
|
| 3 |
import os
|
| 4 |
+
import base64
|
| 5 |
|
| 6 |
handler = EndpointHandler(path="whisper-tiny")
|
| 7 |
|
| 8 |
with open("frank.wav", "rb") as file:
|
| 9 |
audio = file.read()
|
| 10 |
|
| 11 |
+
audio = base64.b64encode(audio)
|
| 12 |
+
|
| 13 |
+
payload = {"inputs": {"audio": audio, "language": "nl", "task": "transcribe"}}
|
| 14 |
|
| 15 |
output = handler(payload)
|
| 16 |
|