Spaces:
Sleeping
Sleeping
wtarit
commited on
Commit
·
7f6b908
1
Parent(s):
591b3b9
add app title
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +11 -3
__pycache__/app.cpython-310.pyc
ADDED
Binary file (965 Bytes). View file
|
|
app.py
CHANGED
@@ -6,13 +6,21 @@ model_repo = "wtarit/nllb-600M-th-en"
|
|
6 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_repo)
|
7 |
tokenizer = NllbTokenizerFast.from_pretrained(model_repo, src_lang="tha_Thai", tgt_lang="eng_Latn")
|
8 |
|
9 |
-
def translate(
|
10 |
-
inputs = tokenizer(
|
11 |
translated_tokens = model.generate(
|
12 |
**inputs, forced_bos_token_id=tokenizer.lang_code_to_id["eng_Latn"], max_length=64
|
13 |
)
|
14 |
return tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
15 |
|
16 |
-
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
demo.launch()
|
|
|
6 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_repo)
|
7 |
tokenizer = NllbTokenizerFast.from_pretrained(model_repo, src_lang="tha_Thai", tgt_lang="eng_Latn")
|
8 |
|
9 |
+
def translate(Text):
|
10 |
+
inputs = tokenizer(Text, return_tensors="pt")
|
11 |
translated_tokens = model.generate(
|
12 |
**inputs, forced_bos_token_id=tokenizer.lang_code_to_id["eng_Latn"], max_length=64
|
13 |
)
|
14 |
return tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
15 |
|
16 |
+
demo = gr.Interface(
|
17 |
+
fn=translate,
|
18 |
+
inputs=[
|
19 |
+
gr.components.Textbox(placeholder="Enter Thai text here...")
|
20 |
+
],
|
21 |
+
outputs=["text"],
|
22 |
+
title="NLLB TH-EN Translation",
|
23 |
+
allow_flagging="never",
|
24 |
+
)
|
25 |
|
26 |
demo.launch()
|