Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
10 |
["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
|
11 |
-
|
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")
|
20 |
return result["text"]
|
21 |
-
|
22 |
-
except FileNotFoundError:
|
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}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import gradio as gr
|
3 |
+
import subprocess
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Load Whisper model
|
7 |
+
model = whisper.load_model("base")
|
8 |
+
|
9 |
def transcribe_video(video_path):
|
10 |
try:
|
|
|
|
|
|
|
|
|
|
|
11 |
audio_path = "audio.wav"
|
12 |
+
subprocess.run(
|
13 |
["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
|
14 |
+
check=True
|
|
|
|
|
15 |
)
|
|
|
|
|
|
|
|
|
16 |
result = model.transcribe(audio_path, task="transcribe", language="ur")
|
17 |
return result["text"]
|
|
|
|
|
|
|
18 |
except Exception as e:
|
19 |
return f"An error occurred: {e}"
|
20 |
+
|
21 |
+
# Gradio Interface
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=transcribe_video,
|
24 |
+
inputs=gr.Video(label="Upload your Urdu-speaking video"),
|
25 |
+
outputs=gr.Textbox(label="Transcribed Text"),
|
26 |
+
title="Urdu Video Transcription App"
|
27 |
+
)
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
interface.launch()
|