Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,25 @@ 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') #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def transcribe_video(video_path):
|
13 |
try:
|
@@ -25,7 +38,10 @@ def transcribe_video(video_path):
|
|
25 |
# Correct the transcribed text using autocorrect
|
26 |
corrected_text = spell(transcribed_text)
|
27 |
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
except FileNotFoundError:
|
31 |
return "Error: ffmpeg is not installed or not found in the environment."
|
@@ -38,7 +54,7 @@ interface = gr.Interface(
|
|
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
|
42 |
)
|
43 |
|
44 |
# Launch the app
|
|
|
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 |
model = whisper.load_model("large")
|
9 |
|
10 |
# Initialize autocorrect for Urdu
|
11 |
+
spell = Speller(lang='ur') # Urdu spelling correction
|
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:
|
|
|
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."
|
|
|
54 |
inputs=gr.Video(label="Upload your Urdu-speaking video"),
|
55 |
outputs=gr.Textbox(label="Corrected Transcribed Text"),
|
56 |
title="Urdu Video Transcription with Correction",
|
57 |
+
description="Upload a video file in Urdu, and this app will transcribe the speech, correct spelling and grammar using Whisper and Transformers.",
|
58 |
)
|
59 |
|
60 |
# Launch the app
|