File size: 2,049 Bytes
ed41184
9c94c47
ed41184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a360176
 
 
ed41184
 
a360176
 
 
 
 
ed41184
 
 
 
 
 
a360176
ed41184
a360176
 
 
 
 
 
 
 
 
 
 
ed41184
 
 
a360176
 
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
49
50
51
52
53
54
55
56
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"
}

# Define Gradio Interface
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:  # Add dark theme
    gr.Markdown("# πŸŽ₯ AI-Powered Video Subtitling")
    gr.Markdown("Upload a video (MP4/MKV/AVI) and select a language to generate subtitles.")

    with gr.Row():
        video_input = gr.File(
            label="Upload Video File",
            file_types=["mp4", "mkv", "avi"],  # Remove dots before extensions
            interactive=True
        )
        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")
    progress = gr.Textbox(label="Progress", interactive=False)  # Add progress updates

    def generate_subtitles(video_file, language):
        try:
            # Extract the file path from Gradio's File object
            video_path = video_file.name  # Get the actual file path
            print(f"Processing video: {video_path}")
            srt_path = process_video(video_path, language)
            return srt_path, "βœ… Subtitles generated successfully!"
        except Exception as e:
            return None, f"❌ Error: {str(e)}"

    generate_button.click(
        generate_subtitles,
        inputs=[video_file, language_dropdown],
        outputs=[output_srt, progress]  # Include progress feedback
    )

demo.launch()