mkozak commited on
Commit
7ce298f
·
verified ·
1 Parent(s): 8aba9e4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -5
main.py CHANGED
@@ -13,15 +13,15 @@ app = FastAPI()
13
 
14
  def process_audio(url: str):
15
  response = requests.get(url)
16
- with open("/tmp/audio.mp3", mode="wb") as file:
17
  file.write(response.content)
18
 
19
 
20
- device = "cpu"
21
 
22
  model_id = "openai/whisper-large-v3"
23
  model = AutoModelForSpeechSeq2Seq.from_pretrained(
24
- model_id, torch_dtype=torch.float32, low_cpu_mem_usage=True, use_safetensors=True
25
  )
26
  model.to(device)
27
 
@@ -35,11 +35,11 @@ def process_audio(url: str):
35
  chunk_length_s=30,
36
  batch_size=16,
37
  return_timestamps=True,
38
- torch_dtype=torch.float32,
39
  device=device
40
  )
41
  dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
42
- whisper_result = pipe("/tmp/audio.mp3")
43
  return whisper_result
44
 
45
 
 
13
 
14
  def process_audio(url: str):
15
  response = requests.get(url)
16
+ with open("/data/audio.mp3", mode="wb") as file:
17
  file.write(response.content)
18
 
19
 
20
+ device = "cuda"
21
 
22
  model_id = "openai/whisper-large-v3"
23
  model = AutoModelForSpeechSeq2Seq.from_pretrained(
24
+ model_id, torch_dtype=torch.float16, low_cpu_mem_usage=True, use_safetensors=True
25
  )
26
  model.to(device)
27
 
 
35
  chunk_length_s=30,
36
  batch_size=16,
37
  return_timestamps=True,
38
+ torch_dtype=torch.float16,
39
  device=device
40
  )
41
  dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
42
+ whisper_result = pipe("/data/audio.mp3")
43
  return whisper_result
44
 
45