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Button(value="Translate")
|
| 9 |
with gr.Column():
|
| 10 |
chatbot = gr.Chatbot().style(color_map=("green", "gray"))
|
|
|
|
| 11 |
|
| 12 |
demo.launch()
|
|
|
|
| 1 |
+
from deep_translator import GoogleTranslator
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import time
|
| 5 |
+
from pytube import YouTube
|
| 6 |
+
|
| 7 |
+
#pipe = pipeline(model="tlord/whisper") # change to "your-username/the-name-you-picked"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
LANGUAGES = {
|
| 11 |
+
'afrikaans' : 'af',
|
| 12 |
+
'albanian' : 'sq',
|
| 13 |
+
'amharic' : 'am',
|
| 14 |
+
'arabic' : 'ar',
|
| 15 |
+
'armenian' : 'hy',
|
| 16 |
+
'azerbaijani' : 'az',
|
| 17 |
+
'basque' : 'eu',
|
| 18 |
+
'belarusian' : 'be',
|
| 19 |
+
'bengali' : 'bn',
|
| 20 |
+
'bosnian' : 'bs',
|
| 21 |
+
'bulgarian' : 'bg',
|
| 22 |
+
'catalan' : 'ca',
|
| 23 |
+
'cebuano' : 'ceb',
|
| 24 |
+
'chichewa' : 'ny',
|
| 25 |
+
'chinese (simplified)' : 'zh-c',
|
| 26 |
+
'chinese (traditional)' : 'zh-t',
|
| 27 |
+
'corsican' : 'co',
|
| 28 |
+
'croatian' : 'hr',
|
| 29 |
+
'czech' : 'cs',
|
| 30 |
+
'danish' : 'da',
|
| 31 |
+
'dutch' : 'nl',
|
| 32 |
+
'english' : 'en',
|
| 33 |
+
'esperanto' : 'eo',
|
| 34 |
+
'estonian' : 'et',
|
| 35 |
+
'filipino' : 'tl',
|
| 36 |
+
'finnish' : 'fi',
|
| 37 |
+
'french' : 'fr',
|
| 38 |
+
'frisian' : 'fy',
|
| 39 |
+
'galician' : 'gl',
|
| 40 |
+
'georgian' : 'ka',
|
| 41 |
+
'german' : 'de',
|
| 42 |
+
'greek' : 'el',
|
| 43 |
+
'gujarati' : 'gu',
|
| 44 |
+
'haitian creole' : 'ht',
|
| 45 |
+
'hausa' : 'ha',
|
| 46 |
+
'hawaiian' : 'haw',
|
| 47 |
+
'hebrew' : 'iw',
|
| 48 |
+
'hebrew' : 'he',
|
| 49 |
+
'hindi' : 'hi',
|
| 50 |
+
'hmong' : 'hmn',
|
| 51 |
+
'hungarian' : 'hu',
|
| 52 |
+
'icelandic' : 'is',
|
| 53 |
+
'igbo' : 'ig',
|
| 54 |
+
'indonesian' : 'id',
|
| 55 |
+
'irish' : 'ga',
|
| 56 |
+
'italian' : 'it',
|
| 57 |
+
'japanese' : 'ja',
|
| 58 |
+
'javanese' : 'jw',
|
| 59 |
+
'kannada' : 'kn',
|
| 60 |
+
'kazakh' : 'kk',
|
| 61 |
+
'khmer' : 'km',
|
| 62 |
+
'korean' : 'ko',
|
| 63 |
+
'kurdish (kurmanji)' : 'ku',
|
| 64 |
+
'kyrgyz' : 'ky',
|
| 65 |
+
'lao' : 'lo',
|
| 66 |
+
'latin' : 'la',
|
| 67 |
+
'latvian' : 'lv',
|
| 68 |
+
'lithuanian' : 'lt',
|
| 69 |
+
'luxembourgish' : 'lb',
|
| 70 |
+
'macedonian' : 'mk',
|
| 71 |
+
'malagasy' : 'mg',
|
| 72 |
+
'malay' : 'ms',
|
| 73 |
+
'malayalam' : 'ml',
|
| 74 |
+
'maltese' : 'mt',
|
| 75 |
+
'maori' : 'mi',
|
| 76 |
+
'marathi' : 'mr',
|
| 77 |
+
'mongolian' : 'mn',
|
| 78 |
+
'myanmar (burmese)' : 'my',
|
| 79 |
+
'nepali' : 'ne',
|
| 80 |
+
'norwegian' : 'no',
|
| 81 |
+
'odia' : 'or',
|
| 82 |
+
'pashto' : 'ps',
|
| 83 |
+
'persian' : 'fa',
|
| 84 |
+
'polish' : 'pl',
|
| 85 |
+
'portuguese' : 'pt',
|
| 86 |
+
'punjabi' : 'pa',
|
| 87 |
+
'romanian' : 'ro',
|
| 88 |
+
'russian' : 'ru',
|
| 89 |
+
'samoan' : 'sm',
|
| 90 |
+
'scots gaelic' : 'gd',
|
| 91 |
+
'serbian' : 'sr',
|
| 92 |
+
'sesotho' : 'st',
|
| 93 |
+
'shona' : 'sn',
|
| 94 |
+
'sindhi' : 'sd',
|
| 95 |
+
'sinhala' : 'si',
|
| 96 |
+
'slovak' : 'sk',
|
| 97 |
+
'slovenian' : 'sl',
|
| 98 |
+
'somali' : 'so',
|
| 99 |
+
'spanish' : 'es',
|
| 100 |
+
'sundanese' : 'su',
|
| 101 |
+
'swahili' : 'sw',
|
| 102 |
+
'tajik' : 'tg',
|
| 103 |
+
'tamil' : 'ta',
|
| 104 |
+
'telugu' : 'te',
|
| 105 |
+
'thai' : 'th',
|
| 106 |
+
'turkish' : 'tr',
|
| 107 |
+
'ukrainian' : 'uk',
|
| 108 |
+
'urdu' : 'ur',
|
| 109 |
+
'uyghur' : 'ug',
|
| 110 |
+
'uzbek' : 'uz',
|
| 111 |
+
'vietnamese' : 'vi',
|
| 112 |
+
'welsh' : 'cy',
|
| 113 |
+
'xhosa' : 'xh',
|
| 114 |
+
'yiddish' : 'yi',
|
| 115 |
+
'yoruba' : 'yo',
|
| 116 |
+
'zulu' : 'zu',
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
def get_soundfile(link):
|
| 120 |
+
yt = YouTube(link)
|
| 121 |
+
audio = yt.streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
|
| 122 |
+
|
| 123 |
+
return audio
|
| 124 |
+
|
| 125 |
+
def translate(message, lang):
|
| 126 |
+
res = GoogleTranslator(source='sv', target=lang).translate(message)
|
| 127 |
+
if res != None and res != "":
|
| 128 |
+
return res
|
| 129 |
+
else:
|
| 130 |
+
return "Error, sorry!"
|
| 131 |
+
|
| 132 |
+
def transcribe(audio, lang, history, link):
|
| 133 |
+
|
| 134 |
+
if link != "":
|
| 135 |
+
audio = get_soundfile(link)
|
| 136 |
+
if lang is None or lang == "":
|
| 137 |
+
lang = 'english'
|
| 138 |
+
history = history or []
|
| 139 |
+
lang_code = LANGUAGES[lang]
|
| 140 |
+
text = pipe(audio)["text"]
|
| 141 |
+
history.append((text, translate(text, lang_code)))
|
| 142 |
+
|
| 143 |
+
return history, history
|
| 144 |
+
|
| 145 |
with gr.Blocks() as demo:
|
| 146 |
history = gr.State([])
|
| 147 |
with gr.Row():
|
|
|
|
| 152 |
submit = gr.Button(value="Translate")
|
| 153 |
with gr.Column():
|
| 154 |
chatbot = gr.Chatbot().style(color_map=("green", "gray"))
|
| 155 |
+
#submit.click(transcribe, inputs=[audio, language, history, link], outputs=[chatbot, history])
|
| 156 |
|
| 157 |
demo.launch()
|