import streamlit as st import tempfile import os from processor import translate_and_dub st.set_page_config(page_title="Video Translator", page_icon="📺") st.title("📺 Video Translator") # --- SIDEBAR --- with st.sidebar: mode = st.radio("Chuyển ngữ", ('Tiếng Việt -> Trung Quốc', 'Trung Quốc -> Tiếng Việt')) gender = st.radio("Giọng", ('Nữ', 'Nam')) target_lang = "Chinese" if mode == 'Tiếng Việt -> Trung Quốc' else "Vietnamese" # --- MAIN --- uploaded_file = st.file_uploader("Upload Video", type=['mp4', 'mov']) if uploaded_file is not None: # Save Upload tfile = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') tfile.write(uploaded_file.read()) video_path = tfile.name st.video(video_path) # Show original if st.button('🚀 Dịch video'): with st.spinner('Đang xử lý...'): try: # Get paths for Video and Subtitle file dubbed_video, subtitle_file, segments = translate_and_dub(video_path, target_lang, gender) st.success("Dịch thành công!") st.subheader("Video đã dịch (Bật CC 💬 trong player)") # THIS IS THE KEY CHANGE: # We pass the video AND the subtitle file path st.video(dubbed_video, subtitles=subtitle_file) col1, col2 = st.columns(2) with col1: with open(dubbed_video, 'rb') as f: st.download_button('⬇️ Tải Video', f, file_name="dubbed_video.mp4") with col2: with open(subtitle_file, 'rb') as f: st.download_button('⬇️ Tải Subtitles', f, file_name="subtitles.vtt") # Show text transcript below with st.expander("Xem bản dịch"): for seg in segments: st.write(f"**{seg['start']}s**: {seg['text']}") except Exception as e: st.error(f"Error: {e}")