adnaniqbal001 commited on
Commit
b0a50ec
·
verified ·
1 Parent(s): d2fe6a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,13 +1,13 @@
1
- import whisper # Ensure 'openai-whisper' is installed
2
  import gradio as gr
3
  import subprocess
 
4
 
5
  # Load the Whisper model
6
- try:
7
- model = whisper.load_model("large") # Official Whisper model
8
- except Exception as e:
9
- print(f"Error loading Whisper model: {e}")
10
- raise e
11
 
12
  def transcribe_video(video_path):
13
  try:
@@ -20,7 +20,12 @@ def transcribe_video(video_path):
20
 
21
  # Transcribe the audio in Urdu
22
  result = model.transcribe(audio_path, task="transcribe", language="ur")
23
- return result["text"]
 
 
 
 
 
24
 
25
  except FileNotFoundError:
26
  return "Error: ffmpeg is not installed or not found in the environment."
@@ -31,9 +36,9 @@ def transcribe_video(video_path):
31
  interface = gr.Interface(
32
  fn=transcribe_video,
33
  inputs=gr.Video(label="Upload your Urdu-speaking video"),
34
- outputs=gr.Textbox(label="Transcribed Text"),
35
- title="Urdu Video Transcription App",
36
- description="Upload a video file in Urdu, and this app will transcribe the speech into text using Whisper.",
37
  )
38
 
39
  # Launch the app
 
1
+ import whisper
2
  import gradio as gr
3
  import subprocess
4
+ from autocorrect import Speller
5
 
6
  # Load the Whisper model
7
+ model = whisper.load_model("large")
8
+
9
+ # Initialize autocorrect for Urdu
10
+ spell = Speller(lang='ur') # Set the language for Urdu
 
11
 
12
  def transcribe_video(video_path):
13
  try:
 
20
 
21
  # Transcribe the audio in Urdu
22
  result = model.transcribe(audio_path, task="transcribe", language="ur")
23
+ transcribed_text = result["text"]
24
+
25
+ # Correct the transcribed text using autocorrect
26
+ corrected_text = spell(transcribed_text)
27
+
28
+ return corrected_text
29
 
30
  except FileNotFoundError:
31
  return "Error: ffmpeg is not installed or not found in the environment."
 
36
  interface = gr.Interface(
37
  fn=transcribe_video,
38
  inputs=gr.Video(label="Upload your Urdu-speaking video"),
39
+ outputs=gr.Textbox(label="Corrected Transcribed Text"),
40
+ title="Urdu Video Transcription with Correction",
41
+ description="Upload a video file in Urdu, and this app will transcribe the speech and correct the text using Whisper and autocorrect.",
42
  )
43
 
44
  # Launch the app