Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
import sys | |
import subprocess | |
import whisper | |
model = whisper.load_model("medium") | |
def video2mp3(video_file, output_ext="mp3"): | |
filename, ext = os.path.splitext(video_file) | |
subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"], | |
stdout=subprocess.DEVNULL, | |
stderr=subprocess.STDOUT) | |
return f"{filename}.{output_ext}" | |
def translate(input_video): | |
audio_file = video2mp3(input_video) | |
model = whisper.load_model("base") | |
audio = whisper.load_audio(audio_file) | |
#result= model.transcribe(audio) | |
options = dict(beam_size=5, best_of=5) | |
translate_options = dict(task="translate", **options) | |
transcribe_options = dict(task="transcribe", **options) | |
result_translate = model.transcribe(audio_file,**translate_options) | |
result_transcribe = model.transcribe(audio_file,**transcribe_options) | |
return result_transcribe["text"] #+" ---Translated text in english ---- "+result_translate["text"] | |
block = gr.Blocks() | |
with block: | |
with gr.Group(): | |
with gr.Box(): | |
with gr.Row().style(): | |
inp_video = gr.Video( | |
label="Input Video", | |
type="filepath", | |
mirror_webcam = False | |
) | |
op_video = gr.Textbox() | |
btn = gr.Button("Generate Subtitle Video") | |
btn.click(translate, inputs=[inp_video], outputs=[op_video],api_name="view_api") | |
block.launch(enable_queue = True,debug=True) |