Aekanun commited on
Commit
24fa852
·
1 Parent(s): 2eb0277
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -3,11 +3,12 @@ from transformers import pipeline
3
  import torch
4
  import spaces
5
 
6
- # Initialize model on CPU
7
  model = pipeline(
8
  "automatic-speech-recognition",
9
  model="Aekanun/whisper-small-hi",
10
- device="cpu"
 
11
  )
12
 
13
  @spaces.GPU
@@ -17,17 +18,12 @@ def transcribe_speech(audio):
17
  if audio is None:
18
  return "กรุณาบันทึกเสียงก่อน"
19
 
20
- # Move model to GPU
21
- model.model = model.model.to("cuda")
22
 
23
  with torch.amp.autocast('cuda'):
24
- # Process audio with chunk length to handle long audio
25
- result = model(
26
- audio,
27
- batch_size=1,
28
- return_timestamps=True, # แก้ error เรื่อง timestamps
29
- chunk_length_s=30 # แก้ error เรื่องความยาวเสียง
30
- )
31
 
32
  # Get text result
33
  text = result["text"] if isinstance(result, dict) else result
 
3
  import torch
4
  import spaces
5
 
6
+ # Initialize model on CPU with float16
7
  model = pipeline(
8
  "automatic-speech-recognition",
9
  model="Aekanun/whisper-small-hi",
10
+ device="cpu",
11
+ torch_dtype=torch.float16 # กำหนด data type เป็น float16
12
  )
13
 
14
  @spaces.GPU
 
18
  if audio is None:
19
  return "กรุณาบันทึกเสียงก่อน"
20
 
21
+ # Move model to GPU with float16
22
+ model.model = model.model.to("cuda").half() # ใช้ .half() เพื่อแปลงเป็น float16
23
 
24
  with torch.amp.autocast('cuda'):
25
+ # Process audio
26
+ result = model(audio, batch_size=1)
 
 
 
 
 
27
 
28
  # Get text result
29
  text = result["text"] if isinstance(result, dict) else result