Spaces:
Running
Running
File size: 4,264 Bytes
67e0b37 faa4b4b 67e0b37 07d263c 67e0b37 faa4b4b 711306a 67e0b37 053e749 0bd3554 67e0b37 71b66d0 7690b77 71b66d0 67e0b37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# coding: utf-8
import gradio as gr
import os
from translation import Translator, LANGUAGES
LANGUAGES_LIST = list(LANGUAGES.keys())
HF_TOKEN = os.environ.get('HF_TOKEN')
def translate_wrapper(text, src_lang, tgt_lang, by_sentence=True, clean=True, num_beams=4):
src_lang = LANGUAGES.get(src_lang)
tgt_lang = LANGUAGES.get(tgt_lang)
result = translator.translate(text, src_lang, tgt_lang, by_sentence=by_sentence, clean=clean, num_beams=num_beams)
return result
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "AriNubar/hyw-en-crowd-source")
desc = "<p>Հոս կը ցուցադրուի առաջին արեւմտահայերէն-անգլերէն մեքենական թարգմանիչը, որ կարուցուած է Մեթայի (Ֆեյսպուքի) 'No Language Left Behind' տիպարի հիման վրայ։ Թարգմանութեան տիպարը կ'աշխատի CPU-ի մը մէջ, ուրեմն նախադասութեան մը թարգմանութիւնը կրնայ տեւել մօտաւորապէս 40-60 երկվայրկեան։ Ձեր գնահատութիւնները եւ քննադատութիւնները շատ կարեւոր են մեզի համար, որոնց հետ տիպարի թարգմանութեան որակը կրնայ բարելաւուիլ։ Շնորհակալութիւն Գալուստ Կիւլպէնկեան Հիմնադրամին, որուն աջակցութեամբ այս նախագիծը իրականացուեցաւ։</p><p></p><p>This is the demo of the first Western Armenian-English neural machine translation system which is based on Meta's 'No Language Left Behind' model. The model runs on a CPU, so it might take approximately 40-60 seconds to translate a single sentence. Your feedback and comments are very important for us to improve the quality of the translation. Thanks to the Calouste Gulbenkian Foundation for making this project possible with their support.</p>"
interface = gr.Interface(
translate_wrapper,
[
gr.Textbox(lines=5, label="Ներմուծման Գրութիւն | Input Text"),
gr.Dropdown(LANGUAGES_LIST, type="value", label="Թարգմանէ Այս Լեզուէ | Source Language"),
gr.Dropdown(LANGUAGES_LIST, type="value", label="Թարգմանէ Այս Լեզուի | Target Language"),
gr.Checkbox(label="Նախադասութիւններու Բաժնէ | Split into Sentences", value=True, info="Տուփը նշանագրեցէք եթէ կ'ուզէք ձեր գրութիւնը թարգմանուի նախադասութիւն առ նախադասութիւն։ Այս կերպով թարգմանուած նախադասութիւններուն որակը աւելի լաւ են։ | Check this box if you want to split your input text into sentences. This way the quality of the translation will be better."),
gr.Checkbox(label="Մշակէ | Preprocess", value=True, info="Տուփը նշանագրեցէք եթէ կ'ուզէք ձեր գրութիւնը կանոնաւորուի ծրագրի կողմէ թարգմանութենէ առաջ։ Կանոնաւորումը թարգմանութեան որակի բարելաւման համար օգտակար է։ | Check this box if you want to preprocess your input text before translation. This way the quality of the translation will be better."),
gr.Dropdown([1, 2, 3, 4, 5], type="value", label="Առնջութեան Շողեր | Number of Beams", value=4, info="Բարձր թիւը ընդհանրապէս կը պատճառէ աւելի բարձր որակի, բայց նոյնիսկ երկարատեւ թարգմանութեան։ | Higher beam size will result in better quality translation, but also longer translation time."),
],
"text",
title="Արեւմտահայերէն-Անգլերէն Մեքենական Թարգմանիչ | Western Armenian-English Machine Translation",
article= desc,
allow_flagging="auto",
flagging_callback=hf_writer,
flagging_options=["Լաւ թարգմանութիւն | Good Translation", "Միջակ թարգմանութիւն | Average Translation", "Վատ թարգմանութիւն | Bad Translation"]
)
if __name__ == "__main__":
translator = Translator()
interface.launch()
|