kabita-choudhary commited on
Commit
ab84c43
1 Parent(s): 465249d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import sys
4
+ import subprocess
5
+
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
+ model = whisper.load_model("base")
24
+
25
+ audio = whisper.load_audio(audio_file)
26
+ #result= model.transcribe(audio)
27
+
28
+ options = dict(beam_size=5, best_of=5)
29
+ translate_options = dict(task="translate", **options)
30
+ transcribe_options = dict(task="transcribe", **options)
31
+ result_translate = model.transcribe(audio_file,**translate_options)
32
+ result_transcribe = model.transcribe(audio_file,**transcribe_options)
33
+
34
+ return "Transcribe result :"+result_transcribe["text"] +"\n ---Translated text in english ---- "+result_translate["text"]
35
+ block = gr.Blocks()
36
+ with block:
37
+
38
+ with gr.Group():
39
+ with gr.Box():
40
+
41
+
42
+
43
+ with gr.Row().style():
44
+
45
+ inp_video = gr.Video(
46
+ label="Input Video",
47
+ type="filepath",
48
+ mirror_webcam = False
49
+ )
50
+ op_video = gr.Textbox()
51
+ btn = gr.Button("Generate Subtitle Video")
52
+
53
+
54
+
55
+
56
+
57
+
58
+ btn.click(translate, inputs=[inp_video], outputs=[op_video],api_name="view_api")
59
+ block.launch(enable_queue = True,debug=True)