File size: 4,643 Bytes
ed41184
fc7755f
ed41184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f596d8
fc7755f
 
 
 
 
 
1f596d8
2670e49
cea609f
 
2670e49
cea609f
2670e49
1f596d8
fc7755f
 
 
 
 
1f596d8
fc7755f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f596d8
2670e49
 
 
cea609f
 
2670e49
cea609f
2670e49
cea609f
2670e49
 
 
 
1f596d8
fc7755f
 
ed41184
 
fc7755f
 
 
ed41184
 
fc7755f
 
 
 
 
 
 
 
 
 
 
 
 
1f596d8
fc7755f
 
 
1f596d8
2670e49
cea609f
2670e49
1f596d8
fc7755f
 
 
ed41184
 
fc7755f
 
 
 
 
 
1f596d8
fc7755f
 
 
 
 
 
 
 
 
 
 
 
1f596d8
e219dd2
2670e49
6147286
b00f500
e219dd2
2670e49
cea609f
2670e49
e219dd2
cea609f
2670e49
e219dd2
2670e49
a360176
2670e49
e219dd2
1f596d8
fc7755f
ed41184
 
 
fc7755f
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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"
}

<<<<<<< HEAD
# Custom CSS for dark mode and animations
css = """
body { 
    background-color: #1a1a1a;
    color: #e0e0e0;
    font-family: 'Arial', sans-serif;
=======
# Custom CSS for a Windows-like professional look
css = """
body {
    background-color: #1a1a1a;
    color: #e0e0e0;
    font-family: 'Segoe UI', sans-serif;
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
}
.gradio-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
<<<<<<< HEAD
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.file-preview {
    border: 2px dashed #6c757d;
    padding: 20px;
    border-radius: 10px;
}
.progress-text {
    font-size: 16px;
    color: #28a745;
    animation: blink 1s infinite;
}
@keyframes blink {
    50% { opacity: 0.5; }
=======
    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-text {
    color: #00ff00;
    font-weight: bold;
    margin-top: 10px;
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
}
"""

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

<<<<<<< HEAD
    generate_button = gr.Button("Generate Subtitles πŸš€")
    progress_text = gr.Textbox(
        label="Progress",
=======
    generate_button = gr.Button("Generate Subtitles πŸš€", elem_classes=["btn-primary"])
    progress_text = gr.Textbox(
        label="Status",
>>>>>>> e219dd283e6bfab4f30d250a687e17c1cc380d47
        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, "❌ Invalid file type. Please upload an MP4, MKV, or AVI file."

<<<<<<< HEAD
            # Update progress
            progress = "πŸ”„ Processing video..."
            yield None, progress  # Initial progress update

            # Process video
            srt_path = process_video(video_file.name, language)
            if srt_path:
                yield gr.File(srt_path), "βœ… Subtitles generated successfully!"
            else:
                yield None, "❌ Error during processing. Check logs."
        except Exception as e:
            yield None, f"❌ Error: {str(e)}"
=======
            # Initialize progress tracking
            progress = gr.Progress(track_tqdm=True)

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

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

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

demo.launch()