Shularp commited on
Commit
31c898f
1 Parent(s): 34116d5

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Gradio Course 02 - upload.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1eA4N71lce8BxJnrON-opJolgLoemJv5d
8
+ """
9
+
10
+ !pip install gradio transformers googletrans==4.0.0rc1 transformers[sentencepiece] --quiet
11
+
12
+ import gradio as gr
13
+ from transformers import pipeline
14
+ from googletrans import Translator
15
+
16
+ model_card = 'Shularp/model-translate-en-to-ar-from-320k-dataset-ar-en-th2301191458'
17
+
18
+ pipe2 = pipeline("translation", model = model_card)
19
+
20
+ def trans_via_google(text,source, target):
21
+ google_trans = Translator() #reduce problem timeout runtime.
22
+ return google_trans.translate(text = text, src = source, dest = target).text
23
+
24
+ def translate_th_ar(text):
25
+ text_en = trans_via_google(text,'th', 'en')
26
+ return pipe2(text_en)[0]['translation_text']
27
+
28
+ translate_th_ar('หิวข้าวจังเลย')
29
+
30
+ with gr.Blocks() as demo:
31
+ with gr.Row():
32
+ with gr.Column():
33
+ english = gr.Textbox(label = 'ข้อความภาษาไทย')
34
+ translate_btn = gr.Button(value = 'Translate')
35
+ with gr.Column():
36
+ arabic = gr.Textbox(label = 'ข้อความภาษาอาหรับ')
37
+ translate_btn.click(translate_th_ar, inputs = english, outputs=arabic)
38
+
39
+ demo.launch()
40
+