Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
4 |
model_name = "dsfsi/nr-en-m2m100-gov"
|
5 |
tokenizer = M2M100Tokenizer.from_pretrained(model_name)
|
@@ -9,25 +9,22 @@ tokenizer.src_lang = "nr"
|
|
9 |
|
10 |
model.config.forced_bos_token_id = tokenizer.get_lang_id("en")
|
11 |
|
12 |
-
translater_nr_en = pipeline(
|
13 |
-
"translation",
|
14 |
-
model=model,
|
15 |
-
tokenizer=tokenizer,
|
16 |
-
)
|
17 |
-
|
18 |
def translate(inp):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
# Update description and article as needed
|
23 |
description = """
|
24 |
<p>
|
25 |
<center>
|
26 |
-
|
27 |
</center>
|
28 |
</p>
|
29 |
"""
|
30 |
-
article = "<p style='text-align: center'><a href='https://huggingface.co/dsfsi/nr-en-m2m100-gov' target='_blank'>by dsfsi</a></p
|
31 |
|
32 |
examples = [
|
33 |
["Ngiyabonga kakhulu ngesipho osinike sona."],
|
@@ -46,3 +43,4 @@ iface = gr.Interface(
|
|
46 |
|
47 |
iface.launch(enable_queue=True)
|
48 |
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
3 |
|
4 |
model_name = "dsfsi/nr-en-m2m100-gov"
|
5 |
tokenizer = M2M100Tokenizer.from_pretrained(model_name)
|
|
|
9 |
|
10 |
model.config.forced_bos_token_id = tokenizer.get_lang_id("en")
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def translate(inp):
|
13 |
+
inputs = tokenizer(inp, return_tensors="pt")
|
14 |
+
|
15 |
+
translated_tokens = model.generate(**inputs, max_length=512, forced_bos_token_id=tokenizer.get_lang_id("en"))
|
16 |
+
|
17 |
+
translated_text = tokenizer.decode(translated_tokens[0], skip_special_tokens=True)
|
18 |
+
return translated_text
|
19 |
|
|
|
20 |
description = """
|
21 |
<p>
|
22 |
<center>
|
23 |
+
isiNdebele to English Translation
|
24 |
</center>
|
25 |
</p>
|
26 |
"""
|
27 |
+
article = "<p style='text-align: center'><a href='https://huggingface.co/dsfsi/nr-en-m2m100-gov' target='_blank'>by dsfsi</a></p>"
|
28 |
|
29 |
examples = [
|
30 |
["Ngiyabonga kakhulu ngesipho osinike sona."],
|
|
|
43 |
|
44 |
iface.launch(enable_queue=True)
|
45 |
|
46 |
+
|