kozakhart commited on
Commit
ca8582b
·
verified ·
1 Parent(s): 372e9fa

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +10 -9
handler.py CHANGED
@@ -1,25 +1,26 @@
1
  # handler.py
2
- import io
3
- import torch
4
- from omnilingual_asr.models.inference.pipeline import ASRInferencePipeline
5
 
6
  class EndpointHandler:
7
  def __init__(self, path=""):
8
- # Load ASR model/tokenizer via official helper
 
 
 
9
  self.pipeline = ASRInferencePipeline(model_card="facebook/omniASR-LLM-7B")
10
 
11
  def __call__(self, data):
12
- # data dict may contain bytes, multipart upload, etc.
13
- # Here we assume audio bytes in "inputs"
 
 
 
14
  audio_bytes = data.get("inputs")
15
  if not audio_bytes:
16
  return {"error": "no audio provided"}
17
 
18
- # convert bytes to temp file, path etc.
19
- import soundfile as sf
20
  f = io.BytesIO(audio_bytes)
21
  audio, sr = sf.read(f)
22
 
23
- # Run transcription
24
  result = self.pipeline.transcribe([audio], batch_size=1)
25
  return {"text": result}
 
1
  # handler.py
 
 
 
2
 
3
  class EndpointHandler:
4
  def __init__(self, path=""):
5
+ # lazy import only inside init
6
+ from omnilingual_asr.models.inference.pipeline import ASRInferencePipeline
7
+
8
+ # Load the omniASR pipeline
9
  self.pipeline = ASRInferencePipeline(model_card="facebook/omniASR-LLM-7B")
10
 
11
  def __call__(self, data):
12
+ # import here so it doesn’t trigger during module load
13
+ import io
14
+ import soundfile as sf
15
+
16
+ # read raw bytes
17
  audio_bytes = data.get("inputs")
18
  if not audio_bytes:
19
  return {"error": "no audio provided"}
20
 
 
 
21
  f = io.BytesIO(audio_bytes)
22
  audio, sr = sf.read(f)
23
 
24
+ # run transcription
25
  result = self.pipeline.transcribe([audio], batch_size=1)
26
  return {"text": result}