adnaniqbal001 commited on
Commit
0105482
·
verified ·
1 Parent(s): 84196e0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ import gradio as gr
3
+ import subprocess
4
+
5
+ # Load the Whisper model
6
+ model = whisper.load_model("large") # Use "large" or "large-v2" for best results
7
+
8
+ def transcribe_video(video_path):
9
+ # Extract audio from the uploaded video
10
+ audio_path = "audio.wav"
11
+ subprocess.run(["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path])
12
+
13
+ # Transcribe the audio in Urdu
14
+ result = model.transcribe(audio_path, task="transcribe", language="ur")
15
+
16
+ # Return the transcribed text
17
+ return result["text"]
18
+
19
+ # Create the Gradio interface
20
+ interface = gr.Interface(
21
+ fn=transcribe_video,
22
+ inputs=gr.Video(label="Upload your Urdu-speaking video"),
23
+ outputs=gr.Textbox(label="Transcribed Text"),
24
+ title="Urdu Video Transcription App",
25
+ description="Upload a video file in Urdu, and this app will transcribe the speech into text using Whisper.",
26
+ )
27
+
28
+ # Launch the app
29
+ if __name__ == "__main__":
30
+ interface.launch()