camparchimedes commited on
Commit
3698f30
·
verified ·
1 Parent(s): 8c6ad91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -44,13 +44,25 @@ summarization_tokenizer = AutoTokenizer.from_pretrained("t5-base")
44
  def transcribe_audio(audio_file):
45
  if audio_file.endswith(".m4a"):
46
  audio_file = convert_to_wav(audio_file)
47
-
48
  start_time = time.time()
49
- output = whisper_pipeline(audio_file)
50
- text = output["text"]
51
- output_time = time.time() - start_time
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  result = f"Time taken: {output_time:.2f} seconds\nNumber of words: {len(text.split())}"
 
54
  return text, result
55
 
56
  # Clean and preprocess text for summarization
 
44
  def transcribe_audio(audio_file):
45
  if audio_file.endswith(".m4a"):
46
  audio_file = convert_to_wav(audio_file)
47
+
48
  start_time = time.time()
 
 
 
49
 
50
+ # Prepare input and attention mask
51
+ inputs = whisper_pipeline.tokenizer(audio_file, return_tensors="pt", padding=True)
52
+ inputs = {k: v.to(device) for k, v in inputs.items()}
53
+
54
+ # Generate the transcription with attention_mask
55
+ output = whisper_pipeline.model.generate(
56
+ inputs['input_ids'],
57
+ attention_mask=inputs['attention_mask']
58
+ )
59
+
60
+ # Decode the output
61
+ text = whisper_pipeline.tokenizer.decode(output[0], skip_special_tokens=True)
62
+
63
+ output_time = time.time() - start_time
64
  result = f"Time taken: {output_time:.2f} seconds\nNumber of words: {len(text.split())}"
65
+
66
  return text, result
67
 
68
  # Clean and preprocess text for summarization