mrmuminov commited on
Commit
9334a23
·
verified ·
1 Parent(s): bce555f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -38,19 +38,29 @@ def _return_yt_html_embed(yt_url):
38
  raise gr.Error("Invalid YouTube URL. Please check and try again.")
39
  return f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"></iframe> </center>'
40
 
41
- # Transcription function
42
- def transcribe(inputs, task):
43
- if inputs is None:
44
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
45
 
46
- text = pipe(
47
- {"input_features": inputs},
 
 
 
 
 
 
 
 
 
 
48
  batch_size=BATCH_SIZE,
49
- generate_kwargs={"task": task, "forced_decoder_ids": None},
50
  return_timestamps=True
51
- )["text"]
52
-
53
- return text
54
 
55
  # Download YouTube audio
56
  def download_yt_audio(yt_url, filename):
 
38
  raise gr.Error("Invalid YouTube URL. Please check and try again.")
39
  return f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"></iframe> </center>'
40
 
41
+ # Transcription function (Fix applied)
42
+ def transcribe(audio_file, task):
43
+ if audio_file is None:
44
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
45
 
46
+ # Read the audio file
47
+ audio_array = ffmpeg_read(audio_file, pipe.feature_extractor.sampling_rate)
48
+
49
+ # Convert to correct input format
50
+ inputs = {
51
+ "raw": np.array(audio_array), # Ensure it's a NumPy array
52
+ "sampling_rate": pipe.feature_extractor.sampling_rate
53
+ }
54
+
55
+ # Perform transcription
56
+ result = pipe(
57
+ inputs,
58
  batch_size=BATCH_SIZE,
59
+ generate_kwargs={"task": task},
60
  return_timestamps=True
61
+ )
62
+
63
+ return result["text"]
64
 
65
  # Download YouTube audio
66
  def download_yt_audio(yt_url, filename):