|
|
|
"""Gradio Course 02 - upload.ipynb |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1eA4N71lce8BxJnrON-opJolgLoemJv5d |
|
""" |
|
|
|
|
|
|
|
import gradio as gr |
|
from transformers import pipeline |
|
from googletrans import Translator |
|
|
|
model_card = 'Shularp/model-translate-en-to-ar-from-320k-dataset-ar-en-th2301191458' |
|
|
|
pipe2 = pipeline("translation", model = model_card) |
|
|
|
def trans_via_google(text,source, target): |
|
google_trans = Translator() |
|
return google_trans.translate(text = text, src = source, dest = target).text |
|
|
|
def translate_th_ar(text): |
|
text_en = trans_via_google(text,'th', 'en') |
|
return pipe2(text_en)[0]['translation_text'] |
|
|
|
translate_th_ar('หิวข้าวจังเลย') |
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
with gr.Column(): |
|
english = gr.Textbox(label = 'ข้อความภาษาไทย') |
|
translate_btn = gr.Button(value = 'Translate') |
|
with gr.Column(): |
|
arabic = gr.Textbox(label = 'ข้อความภาษาอาหรับ') |
|
translate_btn.click(translate_th_ar, inputs = english, outputs=arabic) |
|
|
|
demo.launch() |
|
|
|
|