adnaniqbal001 commited on
Commit
aba0e7d
·
verified ·
1 Parent(s): e1d7952

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,20 +1,32 @@
1
  import whisper
2
  import gradio as gr
3
  import subprocess
 
4
 
5
  # Load the Whisper model
6
- model = whisper.load_model("large") # Use "large" or "large-v2" for best results
 
 
 
 
7
 
8
  def transcribe_video(video_path):
9
- # Extract audio from the uploaded video
10
- audio_path = "audio.wav"
11
- subprocess.run(["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path])
 
 
 
 
12
 
13
- # Transcribe the audio in Urdu
14
- result = model.transcribe(audio_path, task="transcribe", language="ur")
 
15
 
16
- # Return the transcribed text
17
- return result["text"]
 
 
18
 
19
  # Create the Gradio interface
20
  interface = gr.Interface(
 
1
  import whisper
2
  import gradio as gr
3
  import subprocess
4
+ import os
5
 
6
  # Load the Whisper model
7
+ try:
8
+ model = whisper.load_model("large")
9
+ except Exception as e:
10
+ print(f"Error loading Whisper model: {e}")
11
+ raise e
12
 
13
  def transcribe_video(video_path):
14
+ try:
15
+ # Extract audio from the uploaded video
16
+ audio_path = "audio.wav"
17
+ subprocess.run(
18
+ ["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
19
+ check=True
20
+ )
21
 
22
+ # Transcribe the audio in Urdu
23
+ result = model.transcribe(audio_path, task="transcribe", language="ur")
24
+ return result["text"]
25
 
26
+ except FileNotFoundError:
27
+ return "Error: ffmpeg is not installed or not found in the environment."
28
+ except Exception as e:
29
+ return f"An error occurred: {e}"
30
 
31
  # Create the Gradio interface
32
  interface = gr.Interface(