Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,19 @@
|
|
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-v3") # 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:
|
|
|
|
|
|
|
|
|
14 |
# Extract audio from the uploaded video
|
15 |
audio_path = "audio.wav"
|
16 |
-
subprocess.run(
|
17 |
["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
|
18 |
-
|
|
|
|
|
19 |
)
|
|
|
|
|
20 |
|
21 |
# Transcribe the audio in Urdu
|
22 |
result = model.transcribe(audio_path, task="transcribe", language="ur")
|
@@ -26,16 +23,3 @@ def transcribe_video(video_path):
|
|
26 |
return "Error: ffmpeg is not installed or not found in the environment."
|
27 |
except Exception as e:
|
28 |
return f"An error occurred: {e}"
|
29 |
-
|
30 |
-
# Create the Gradio interface
|
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
|
40 |
-
if __name__ == "__main__":
|
41 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
def transcribe_video(video_path):
|
2 |
try:
|
3 |
+
# Debug: Check if the video file exists
|
4 |
+
if not os.path.exists(video_path):
|
5 |
+
return f"Error: File not found at {video_path}"
|
6 |
+
|
7 |
# Extract audio from the uploaded video
|
8 |
audio_path = "audio.wav"
|
9 |
+
process = subprocess.run(
|
10 |
["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
|
11 |
+
stdout=subprocess.PIPE,
|
12 |
+
stderr=subprocess.PIPE,
|
13 |
+
text=True
|
14 |
)
|
15 |
+
if process.returncode != 0:
|
16 |
+
return f"ffmpeg error: {process.stderr}"
|
17 |
|
18 |
# Transcribe the audio in Urdu
|
19 |
result = model.transcribe(audio_path, task="transcribe", language="ur")
|
|
|
23 |
return "Error: ffmpeg is not installed or not found in the environment."
|
24 |
except Exception as e:
|
25 |
return f"An error occurred: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|