File size: 1,512 Bytes
ed41184
9c94c47
ed41184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c94c47
ed41184
 
 
 
 
 
 
 
 
9c94c47
ed41184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
from utils import process_video

# Define supported languages
language_map = {
    "English": None,
    "Hindi": "Helsinki-NLP/opus-mt-en-hi",
    "Spanish": "Helsinki-NLP/opus-mt-en-es",
    "French": "Helsinki-NLP/opus-mt-en-fr",
    "German": "Helsinki-NLP/opus-mt-en-de",
    "Telugu": "facebook/nllb-200-distilled-600M",
    "Portuguese": "Helsinki-NLP/opus-mt-en-pt",
    "Russian": "Helsinki-NLP/opus-mt-en-ru",
    "Chinese": "Helsinki-NLP/opus-mt-en-zh",
    "Arabic": "Helsinki-NLP/opus-mt-en-ar",
    "Japanese": "Helsinki-NLP/opus-mt-en-jap"
}

def generate_subtitles(video_file, language):
    try:
        srt_path = process_video(video_file, language)
        return srt_path
    except Exception as e:
        return f"Error: {str(e)}"

# Define Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# AI-Powered Video Subtitling")
    gr.Markdown("Upload a video and select a language to generate subtitles.")

    with gr.Row():
        video_input = gr.Video(label="Upload Video File", format="mp4")  # Use gr.Video instead of gr.File
        language_dropdown = gr.Dropdown(
            choices=list(language_map.keys()),
            label="Select Subtitle Language",
            value="English"
        )

    generate_button = gr.Button("Generate Subtitles")
    output_srt = gr.File(label="Download Subtitles")

    generate_button.click(
        generate_subtitles,
        inputs=[video_input, language_dropdown],
        outputs=output_srt
    )

demo.launch()