Spaces:
Sleeping
Sleeping
nroggendorff
commited on
Commit
•
ce9586d
1
Parent(s):
e4032ff
Make it thicc
Browse files
app.py
CHANGED
@@ -1,54 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
from translation import Translator, LANGUAGES, MODEL_URL
|
5 |
-
LANGUAGES_LIST = list(LANGUAGES.keys())
|
6 |
-
|
7 |
-
|
8 |
-
def translate_wrapper(text, src, trg, by_sentence=True, preprocess=True, random=False, num_beams=4):
|
9 |
-
src_lang = LANGUAGES.get(src)
|
10 |
-
tgt_lang = LANGUAGES.get(trg)
|
11 |
-
# if src == trg:
|
12 |
-
# return 'Please choose two different languages'
|
13 |
-
result = translator.translate(
|
14 |
-
text=text,
|
15 |
-
src_lang=src_lang,
|
16 |
-
tgt_lang=tgt_lang,
|
17 |
-
do_sample=random,
|
18 |
-
num_beams=int(num_beams),
|
19 |
-
by_sentence=by_sentence,
|
20 |
-
preprocess=preprocess,
|
21 |
-
)
|
22 |
-
return result
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
The model itself is available at https://huggingface.co/{MODEL_URL}
|
29 |
-
|
30 |
-
If you want to host in on your own backend, consider running this dockerized app: https://github.com/slone-nlp/nllb-docker-demo.
|
31 |
-
"""
|
32 |
|
|
|
|
|
|
|
|
|
33 |
|
34 |
interface = gr.Interface(
|
35 |
-
|
36 |
-
[
|
37 |
-
gr.Textbox(label="Text", lines=2,
|
38 |
-
gr.Dropdown(
|
39 |
-
gr.Dropdown(
|
40 |
-
gr.Checkbox(label="
|
41 |
-
gr.Checkbox(label="
|
42 |
-
gr.Checkbox(label="
|
43 |
-
gr.
|
44 |
],
|
45 |
-
"text",
|
46 |
-
title='Erzya-Russian
|
47 |
-
article=
|
48 |
)
|
49 |
|
50 |
-
|
51 |
if __name__ == '__main__':
|
52 |
-
|
53 |
-
|
54 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import threading
|
|
|
3 |
from translation import Translator, LANGUAGES, MODEL_URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
translator = Translator()
|
6 |
+
lang_list = list(LANGUAGES.keys())
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
@gr.cache
|
9 |
+
def translate(text, src, trg, **kwargs):
|
10 |
+
src_lang, tgt_lang = LANGUAGES.get(src), LANGUAGES.get(trg)
|
11 |
+
return translator.translate(text, src_lang, tgt_lang, **kwargs)
|
12 |
|
13 |
interface = gr.Interface(
|
14 |
+
fn=translate,
|
15 |
+
inputs=[
|
16 |
+
gr.Textbox(label="Text", lines=2, description="Enter the text you want to translate."),
|
17 |
+
gr.Dropdown(lang_list, type="value", label='Source Language', value=lang_list[0], description="Select the language of the input text."),
|
18 |
+
gr.Dropdown(lang_list, type="value", label='Target Language', value=lang_list[1], description="Select the language you want to translate to."),
|
19 |
+
gr.Checkbox(label="By Sentence", value=True, description="Translate the text sentence by sentence."),
|
20 |
+
gr.Checkbox(label="Preprocess", value=True, description="Preprocess the text before translation."),
|
21 |
+
gr.Checkbox(label="Randomize", value=False, description="Randomize the translation output."),
|
22 |
+
gr.Slider(value=4, label="Number of Beams", minimum=1, maximum=5, step=1, description="Select the number of beams for the translation process.")
|
23 |
],
|
24 |
+
outputs="text",
|
25 |
+
title='Erzya-Russian Translation',
|
26 |
+
article=f"Model: https://huggingface.co/{MODEL_URL}"
|
27 |
)
|
28 |
|
|
|
29 |
if __name__ == '__main__':
|
30 |
+
threading.Thread(target=interface.launch, kwargs=dict(share=True, server_name="0.0.0.0", server_port=7860)).start()
|
|
|
|