File size: 3,503 Bytes
ed41184
2670e49
ed41184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2670e49
cea609f
 
2670e49
cea609f
2670e49
cea609f
 
 
 
 
2670e49
 
 
cea609f
 
2670e49
cea609f
2670e49
cea609f
2670e49
 
 
 
cea609f
2670e49
 
 
 
cea609f
 
 
ed41184
cea609f
a360176
 
ed41184
 
cea609f
 
 
2670e49
cea609f
 
 
 
 
 
 
 
b00f500
2670e49
 
cea609f
2670e49
cea609f
 
 
ed41184
a360176
 
 
b00f500
 
2670e49
b00f500
2670e49
 
 
6147286
b00f500
2670e49
cea609f
2670e49
 
cea609f
2670e49
 
 
a360176
2670e49
 
ed41184
 
 
cea609f
2670e49
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import gradio as gr
from utils import process_video  # Ensure this points to the updated utils.py

# 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"
}

# Custom CSS for a Windows-like professional look
css = """
body {
    background-color: #1a1a1a;
    color: #e0e0e0;
    font-family: 'Segoe UI', sans-serif;
}
.gradio-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    border-radius: 8px;
    background: #2d2d2d;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.file-preview {
    border: 2px dashed #007acc;
    padding: 20px;
    border-radius: 8px;
}
.progress-bar {
    background: #007acc;
    border-radius: 8px;
    height: 20px;
}
.progress-text {
    color: #00ff00;
    font-weight: bold;
    margin-top: 10px;
}
"""

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

    with gr.Row():
        with gr.Column(scale=2):
            video_input = gr.File(
                label="Upload Video File",
                file_types=["mp4", "mkv", "avi"],
                elem_classes=["file-preview"]
            )
        with gr.Column(scale=1):
            language_dropdown = gr.Dropdown(
                choices=list(language_map.keys()),
                label="Select Subtitle Language",
                value="English"
            )

    generate_button = gr.Button("Generate Subtitles πŸš€", elem_classes=["btn-primary"])
    progress_bar = gr.ProgressBar(label="Progress", elem_classes=["progress-bar"])
    progress_text = gr.Textbox(
        label="Status",
        interactive=False,
        elem_classes=["progress-text"]
    )
    output_srt = gr.File(label="Download Subtitles")

    def generate_subtitles(video_file, language):
        try:
            # Validate file type
            if not video_file.name.lower().endswith(('.mp4', '.mkv', '.avi')):
                return None, None, "❌ Invalid file type. Please upload an MP4, MKV, or AVI file."

            # Initialize progress
            progress = gr.Progress(track_tqdm=True)
            progress(0, desc="Initializing...")

            # Process video
            srt_path = process_video(video_file.name, language, progress=progress)
            if srt_path:
                progress(1, desc="βœ… Subtitles generated successfully!")
                return gr.File(srt_path), progress(1), "βœ… Subtitles ready for download!"
            else:
                progress(0, desc="❌ Error during processing.")
                return None, progress(0), "❌ Failed to generate subtitles. Check logs."

        except Exception as e:
            progress(0, desc="❌ Error encountered.")
            return None, progress(0), f"❌ Error: {str(e)}"

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

demo.launch()