ganesh-dhumal's picture
create app.py
53e8252 verified
raw
history blame
2.22 kB
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi as yta
from deep_translator import GoogleTranslator
opts = ['Afrikaans', 'Albanian', 'Amharic', 'Arabic', 'Armenian', 'Azerbaijani', 'Basque', 'Belarusian', 'Bengali', 'Bosnian', 'Bulgarian', 'Catalan', 'Cebuano', 'Chichewa', 'Chinese (Simplified)', 'Chinese (Traditional)', 'Corsican', 'Croatian', 'Czech', 'Danish', 'Dutch', 'English', 'Esperanto', 'Estonian', 'Filipino', 'Finnish', 'French', 'Frisian', 'Galician', 'Georgian', 'German', 'Greek', 'Gujarati', 'Haitian Creole', 'Hausa', 'Hawaiian', 'Hebrew', 'Hindi', 'Hmong', 'Hungarian', 'Icelandic', 'Igbo', 'Indonesian', 'Irish', 'Italian', 'Japanese', 'Javanese', 'Kannada', 'Kazakh', 'Khmer', 'Korean', 'Kurdish (Kurmanji)', 'Kyrgyz', 'Lao', 'Latin', 'Latvian', 'Lithuanian', 'Luxembourgish', 'Macedonian', 'Malagasy', 'Malay', 'Malayalam', 'Maltese', 'Maori', 'Marathi', 'Mongolian', 'Myanmar (Burmese)', 'Nepali', 'Norwegian', 'Odia', 'Pashto', 'Persian', 'Polish', 'Portuguese', 'Punjabi', 'Romanian', 'Russian', 'Samoan', 'Scots Gaelic', 'Serbian', 'Sesotho', 'Shona', 'Sindhi', 'Sinhala', 'Slovak', 'Slovenian', 'Somali', 'Spanish', 'Sundanese', 'Swahili', 'Swedish', 'Tajik', 'Tamil', 'Telugu', 'Thai', 'Turkish', 'Ukrainian', 'Urdu', 'Uyghur', 'Uzbek', 'Vietnamese', 'Welsh', 'Xhosa', 'Yiddish', 'Yoruba', 'Zulu']
def translate_video_transcript(link, target_language):
video_id = link.split("v=")[1]
transcript = yta.get_transcript(video_id)
original_text = "\n".join([line['text'] for line in transcript])
translated_text = GoogleTranslator(source='auto', target=target_language).translate(original_text)
return original_text, translated_text
interface = gr.Interface(fn=translate_video_transcript,
inputs=["text", gr.inputs.Textbox(label="Enter YouTube Video Link"),
gr.inputs.Dropdown(opts, label="Select Language to Translate To")],
outputs=["text", "text"],
title="YouTube Video Transcript Translator",
description="Translate the transcript of any YouTube video to the language of your choice.")
interface.launch()