Spaces:
Sleeping
Sleeping
| 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() |