File size: 2,274 Bytes
06490e9
 
f9b294f
06490e9
 
 
3e6ca13
 
06490e9
3e6ca13
f9b294f
3e6ca13
 
 
 
06490e9
f9b294f
3e6ca13
 
f9b294f
06490e9
3e6ca13
 
f9b294f
 
70f9574
3e6ca13
f9b294f
 
3e6ca13
 
f9b294f
3e6ca13
 
 
f9b294f
06490e9
f9b294f
70f9574
f9b294f
 
06490e9
3e6ca13
 
 
 
 
 
 
 
 
 
 
06490e9
f9b294f
3e6ca13
 
06490e9
f9b294f
3e6ca13
 
f9b294f
3e6ca13
f9b294f
3e6ca13
 
06490e9
3e6ca13
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
import gradio as gr
import whisper
import moviepy.editor as mp
import tempfile
import os

# Load Whisper model (tiny = fast, small = accurate)
model = whisper.load_model("tiny")

def generate_subtitles(video_path):
    try:
        # Create temporary directory
        temp_dir = tempfile.mkdtemp()
        input_path = os.path.join(temp_dir, "input.mp4")
        os.rename(video_path, input_path)

        # Extract audio
        clip = mp.VideoFileClip(input_path)
        audio_path = os.path.join(temp_dir, "audio.wav")
        clip.audio.write_audiofile(audio_path, logger=None)

        # Transcribe audio using Whisper
        result = model.transcribe(audio_path)
        text = result["text"]
        lang = result["language"]

        # Make green background video
        w, h = clip.size
        bg = mp.ColorClip(size=(w, h), color=(0, 255, 0), duration=clip.duration)

        # Combine background + video
        final = mp.CompositeVideoClip([bg, clip.set_position("center")])

        # Save final video
        output_path = os.path.join(temp_dir, "output.mp4")
        final.write_videofile(output_path, codec="libx264", audio_codec="aac", logger=None)

        return output_path, lang, text

    except Exception as e:
        return None, "Error", str(e)


# ----------- UI (VOZO Blink Style) -----------
with gr.Blocks(title="VOZO-style Auto Subtitle Generator") as demo:
    gr.Markdown(
        """
        # 🎬 **Auto Subtitle Generator (VOZO Blink Style)**
        Upload any short Hindi, English, Hinglish, or Indian English video.<br>
        This AI auto-detects the language and generates subtitles with a green background overlay.<br>
        _(Inspired by Blink Captions / VOZO)_
        """
    )

    with gr.Row():
        input_video = gr.Video(label="πŸŽ₯ Upload your video", interactive=True)
        output_video = gr.Video(label="πŸ“Ί Subtitled Output")

    with gr.Row():
        detected_lang = gr.Textbox(label="🌐 Detected Language")
        subtitle_text = gr.Textbox(label="πŸ“ Generated Subtitles")

    run_btn = gr.Button("πŸš€ Generate Subtitles", variant="primary")

    run_btn.click(fn=generate_subtitles, inputs=[input_video],
                  outputs=[output_video, detected_lang, subtitle_text])

demo.launch()