Update handler.py
Browse files- handler.py +4 -2
handler.py
CHANGED
|
@@ -3,13 +3,15 @@ from transformers import pipeline
|
|
| 3 |
from datasets import load_dataset
|
| 4 |
import soundfile as sf
|
| 5 |
from huggingface_hub.inference_api import InferenceApi
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class EndpointHandler:
|
| 8 |
-
def __init__(self):
|
| 9 |
self.api = InferenceApi(repo_id="microsoft/speecht5_tts", task="text-to-speech")
|
| 10 |
self.embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
| 11 |
|
| 12 |
-
def __call__(self, data):
|
| 13 |
text = data.get("inputs", "")
|
| 14 |
# Extract speaker_embedding using the index from your dataset, or replace with your own logic.
|
| 15 |
speaker_embedding = torch.tensor(self.embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
|
|
|
| 3 |
from datasets import load_dataset
|
| 4 |
import soundfile as sf
|
| 5 |
from huggingface_hub.inference_api import InferenceApi
|
| 6 |
+
from typing import Dict, List, Any
|
| 7 |
+
|
| 8 |
|
| 9 |
class EndpointHandler:
|
| 10 |
+
def __init__(self, path=""):
|
| 11 |
self.api = InferenceApi(repo_id="microsoft/speecht5_tts", task="text-to-speech")
|
| 12 |
self.embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
| 13 |
|
| 14 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 15 |
text = data.get("inputs", "")
|
| 16 |
# Extract speaker_embedding using the index from your dataset, or replace with your own logic.
|
| 17 |
speaker_embedding = torch.tensor(self.embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|