rafaaa2105 commited on
Commit
3507ce7
·
verified ·
1 Parent(s): b748e14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -32,9 +32,8 @@ pipe = pipeline(
32
  model=model,
33
  tokenizer=processor.tokenizer,
34
  feature_extractor=processor.feature_extractor,
35
- max_new_tokens=445, # 448 max_target_positions - 3 special tokens = 445
36
  chunk_length_s=30,
37
- batch_size=16,
38
  return_timestamps="word", # CrisperWhisper provides accurate word-level timestamps
39
  torch_dtype=torch_dtype,
40
  device=device,
@@ -75,16 +74,25 @@ def transcribe_audio_chunk(audio_input, task="transcribe", language=None):
75
  Transcribe a single audio chunk with CrisperWhisper.
76
  This model is specifically trained for verbatim transcription.
77
  """
78
- generate_kwargs = {
79
- "task": task,
80
- }
81
-
82
- if language:
83
- generate_kwargs["language"] = language
84
-
85
- # CrisperWhisper automatically provides verbatim transcription
86
- result = pipe(audio_input, generate_kwargs=generate_kwargs)
87
- return result
 
 
 
 
 
 
 
 
 
88
 
89
  def transcribe_audio(audio, task="transcribe", return_timestamps=False, language=None, progress=gr.Progress()):
90
  """
 
32
  model=model,
33
  tokenizer=processor.tokenizer,
34
  feature_extractor=processor.feature_extractor,
 
35
  chunk_length_s=30,
36
+ batch_size=8, # Reduced batch size for stability
37
  return_timestamps="word", # CrisperWhisper provides accurate word-level timestamps
38
  torch_dtype=torch_dtype,
39
  device=device,
 
74
  Transcribe a single audio chunk with CrisperWhisper.
75
  This model is specifically trained for verbatim transcription.
76
  """
77
+ try:
78
+ generate_kwargs = {
79
+ "task": task,
80
+ }
81
+
82
+ if language:
83
+ generate_kwargs["language"] = language
84
+
85
+ # CrisperWhisper automatically provides verbatim transcription
86
+ result = pipe(audio_input, generate_kwargs=generate_kwargs)
87
+ return result
88
+ except Exception as e:
89
+ # Fallback: try without generate_kwargs if there's a tensor mismatch
90
+ print(f"Error with generate_kwargs: {e}")
91
+ try:
92
+ result = pipe(audio_input)
93
+ return result
94
+ except Exception as e2:
95
+ raise Exception(f"Transcription failed: {str(e2)}")
96
 
97
  def transcribe_audio(audio, task="transcribe", return_timestamps=False, language=None, progress=gr.Progress()):
98
  """