-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnllb200_trial.py
More file actions
80 lines (55 loc) · 1.62 KB
/
Copy pathnllb200_trial.py
File metadata and controls
80 lines (55 loc) · 1.62 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import marimo
__generated_with = "0.13.4"
app = marimo.App(width="medium")
@app.cell
def _():
import marimo as mo
return (mo,)
@app.cell
def _():
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline, WhisperProcessor, WhisperForConditionalGeneration
return AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
@app.cell
def _(AutoModelForSeq2SeqLM, AutoTokenizer):
checkpoint = r'facebook/nllb-200-distilled-600M'
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
return model, tokenizer
@app.cell
def _():
target_lang = r'eng_Latn'
source_lang = r'yue_Hant'
return source_lang, target_lang
@app.cell
def _(model, pipeline, source_lang, target_lang, tokenizer):
translator = pipeline(task='translation', model=model, tokenizer=tokenizer, src_lang= source_lang, tgt_lang= target_lang, max_length=400)
return (translator,)
@app.cell
def _(translator):
def get_trans(input_txt:str):
output = translator(input_txt)
translated_text = output[0]['translation_text']
print(translated_text)
return
@app.cell
def _(mo):
t_src_txt = mo.ui.text_area(full_width=True, label='Cantonese To English',value='enter Cantonese here').form(submit_button_label='Confirm')
t_src_txt
return (t_src_txt,)
@app.cell
def _(t_src_txt):
t_src_txt.value
return
@app.cell
def _(t_src_txt, translator):
tr = translator(t_src_txt.value)
return (tr,)
@app.cell
def _(tr):
tr[0]['translation_text']
return
@app.cell
def _():
return
if __name__ == "__main__":
app.run()