Pushkar0655g's picture
Update app.py
a360176 verified
raw
history blame
2.05 kB
import gradio as gr
from utils import process_video
# 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"
}
# Define Gradio Interface
with gr.Blocks(theme=gr.themes.Monochrome()) as demo: # Add dark theme
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"], # Remove dots before extensions
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) # Add progress updates
def generate_subtitles(video_file, language):
try:
# Extract the file path from Gradio's File object
video_path = video_file.name # Get the actual file path
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] # Include progress feedback
)
demo.launch()