|
import gradio as gr |
|
from utils import process_video |
|
|
|
|
|
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" |
|
} |
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Monochrome()) 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(): |
|
video_input = gr.File( |
|
label="Upload Video File", |
|
file_types=["mp4", "mkv", "avi"], |
|
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) |
|
|
|
def generate_subtitles(video_file, language): |
|
try: |
|
|
|
video_path = video_file.name |
|
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] |
|
) |
|
|
|
demo.launch() |