Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,32 @@
|
|
1 |
import whisper
|
2 |
import gradio as gr
|
3 |
import subprocess
|
|
|
4 |
|
5 |
# Load the Whisper model
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def transcribe_video(video_path):
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
|
19 |
# Create the Gradio interface
|
20 |
interface = gr.Interface(
|
|
|
1 |
import whisper
|
2 |
import gradio as gr
|
3 |
import subprocess
|
4 |
+
import os
|
5 |
|
6 |
# Load the Whisper model
|
7 |
+
try:
|
8 |
+
model = whisper.load_model("large")
|
9 |
+
except Exception as e:
|
10 |
+
print(f"Error loading Whisper model: {e}")
|
11 |
+
raise e
|
12 |
|
13 |
def transcribe_video(video_path):
|
14 |
+
try:
|
15 |
+
# Extract audio from the uploaded video
|
16 |
+
audio_path = "audio.wav"
|
17 |
+
subprocess.run(
|
18 |
+
["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
|
19 |
+
check=True
|
20 |
+
)
|
21 |
|
22 |
+
# Transcribe the audio in Urdu
|
23 |
+
result = model.transcribe(audio_path, task="transcribe", language="ur")
|
24 |
+
return result["text"]
|
25 |
|
26 |
+
except FileNotFoundError:
|
27 |
+
return "Error: ffmpeg is not installed or not found in the environment."
|
28 |
+
except Exception as e:
|
29 |
+
return f"An error occurred: {e}"
|
30 |
|
31 |
# Create the Gradio interface
|
32 |
interface = gr.Interface(
|