kabita-choudhary commited on
Commit
ccdaaed
·
1 Parent(s): d875b94

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import sys
4
+ import subprocess
5
+ #from moviepy.editor import VideoFileClip
6
+
7
+ import whisper
8
+ from whisper.utils import write_vtt
9
+
10
+ model = whisper.load_model("medium")
11
+
12
+ def video2mp3(video_file, output_ext="mp3"):
13
+ filename, ext = os.path.splitext(video_file)
14
+ subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"],
15
+ stdout=subprocess.DEVNULL,
16
+ stderr=subprocess.STDOUT)
17
+ return f"{filename}.{output_ext}"
18
+
19
+
20
+ def translate(input_video):
21
+
22
+ audio_file = video2mp3(input_video)
23
+
24
+ options = dict(beam_size=5, best_of=5)
25
+ translate_options = dict(task="translate", **options)
26
+ result = model.transcribe(audio_file,**translate_options)
27
+ return result["text"]
28
+ block = gr.Blocks()
29
+ with block:
30
+
31
+ with gr.Group():
32
+ with gr.Box():
33
+
34
+
35
+
36
+ with gr.Row().style():
37
+
38
+ inp_video = gr.Video(
39
+ label="Input Video",
40
+ type="filepath",
41
+ mirror_webcam = False
42
+ )
43
+ op_video = gr.Textbox()
44
+ btn = gr.Button("Generate Subtitle Video")
45
+
46
+
47
+
48
+
49
+
50
+
51
+ btn.click(translate, inputs=[inp_video], outputs=[op_video])
52
+ block.launch(enable_queue = True)