Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,13 @@
|
|
1 |
-
import whisper
|
2 |
import gradio as gr
|
3 |
import subprocess
|
4 |
-
from autocorrect import Speller
|
5 |
-
from transformers import pipeline
|
6 |
|
7 |
# Load the Whisper model
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# Load the transformer model for text correction
|
14 |
-
corrector = pipeline("text-generation", model="dbmdz/bert-large-uncased-finetuned-urdu")
|
15 |
-
|
16 |
-
def correct_urdu_text(text):
|
17 |
-
try:
|
18 |
-
# Use the transformer model to correct the Urdu text
|
19 |
-
corrected_text = corrector(text, max_length=512, num_return_sequences=1)[0]['generated_text']
|
20 |
-
return corrected_text
|
21 |
-
except Exception as e:
|
22 |
-
print(f"Error in text correction: {e}")
|
23 |
-
return text
|
24 |
|
25 |
def transcribe_video(video_path):
|
26 |
try:
|
@@ -33,15 +20,7 @@ def transcribe_video(video_path):
|
|
33 |
|
34 |
# Transcribe the audio in Urdu
|
35 |
result = model.transcribe(audio_path, task="transcribe", language="ur")
|
36 |
-
|
37 |
-
|
38 |
-
# Correct the transcribed text using autocorrect
|
39 |
-
corrected_text = spell(transcribed_text)
|
40 |
-
|
41 |
-
# Apply further correction using transformer-based model
|
42 |
-
final_corrected_text = correct_urdu_text(corrected_text)
|
43 |
-
|
44 |
-
return final_corrected_text
|
45 |
|
46 |
except FileNotFoundError:
|
47 |
return "Error: ffmpeg is not installed or not found in the environment."
|
@@ -52,9 +31,9 @@ def transcribe_video(video_path):
|
|
52 |
interface = gr.Interface(
|
53 |
fn=transcribe_video,
|
54 |
inputs=gr.Video(label="Upload your Urdu-speaking video"),
|
55 |
-
outputs=gr.Textbox(label="
|
56 |
-
title="Urdu Video Transcription
|
57 |
-
description="Upload a video file in Urdu, and this app will transcribe the speech
|
58 |
)
|
59 |
|
60 |
# Launch the app
|
|
|
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 |
|
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 |
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
|