import requests API_URL = "https://api-inference.huggingface.co/models/jkang/espnet2_librispeech_100_conformer_word" headers = {"Authorization": f"Bearer {API_TOKEN}"} def query(filename): with open(filename, "rb") as f: data = f.read() response = requests.post(API_URL, headers=headers, data=data) return response.json() output = query("sample1.flac")

#4
by Kirkawin - opened
Files changed (1) hide show
  1. handler.py +9 -31
handler.py CHANGED
@@ -1,34 +1,12 @@
1
- from typing import Dict, List, Any
2
- from optimum.onnxruntime import ORTModelForSequenceClassification
3
- from transformers import pipeline, AutoTokenizer
4
 
 
 
5
 
6
- class EndpointHandler():
7
- def __init__(self, path=""):
8
- # load the optimized model
9
- model = ORTModelForSequenceClassification.from_pretrained(path)
10
- tokenizer = AutoTokenizer.from_pretrained(path)
11
- # create inference pipeline
12
- self.pipeline = pipeline("text-classification", model=model, tokenizer=tokenizer)
13
 
14
-
15
- def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
16
- """
17
- Args:
18
- data (:obj:):
19
- includes the input data and the parameters for the inference.
20
- Return:
21
- A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
22
- - "label": A string representing what the label/class is. There can be multiple labels.
23
- - "score": A score between 0 and 1 describing how confident the model is for this label/class.
24
- """
25
- inputs = data.pop("inputs", data)
26
- parameters = data.pop("parameters", None)
27
-
28
- # pass inputs with all kwargs in data
29
- if parameters is not None:
30
- prediction = self.pipeline(inputs, **parameters)
31
- else:
32
- prediction = self.pipeline(inputs)
33
- # postprocess the prediction
34
- return prediction
 
1
+ import requests
 
 
2
 
3
+ API_URL = "https://api-inference.huggingface.co/models/jkang/espnet2_librispeech_100_conformer_word"
4
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
5
 
6
+ def query(filename):
7
+ with open(filename, "rb") as f:
8
+ data = f.read()
9
+ response = requests.post(API_URL, headers=headers, data=data)
10
+ return response.json()
 
 
11
 
12
+ output = query("sample1.flac")