File size: 3,060 Bytes
ed41184 fc7755f ed41184 fc7755f ed41184 fc7755f ed41184 fc7755f ed41184 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 |
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 dark mode and animations
css = """
body {
background-color: #1a1a1a;
color: #e0e0e0;
font-family: 'Arial', sans-serif;
}
.gradio-container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
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; }
}
"""
# 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 π")
progress_text = gr.Textbox(
label="Progress",
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."
# 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)}"
generate_button.click(
generate_subtitles,
inputs=[video_input, language_dropdown],
outputs=[output_srt, progress_text]
)
demo.launch() |