Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
|
|
4 |
|
5 |
-
# 加载模型和处理器
|
6 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
7 |
|
8 |
def greet(text,src_lang,tgt_lang):
|
9 |
# 输入文本
|
10 |
-
|
11 |
-
|
12 |
-
input_ids = tokenizer.encode(text, return_tensors="pt")
|
13 |
-
outputs = model.generate(input_ids, )
|
14 |
-
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
-
return decoded
|
16 |
|
17 |
text = gr.Textbox(lines=5,label="输入文本",placeholder="请输入文本")
|
18 |
src_lang = gr.Dropdown(label="源语言",choices=["afr_Latn",
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
pipe = pipeline(task="translation", model="facebook/nllb-200-distilled-600M")
|
5 |
|
|
|
|
|
6 |
|
7 |
def greet(text,src_lang,tgt_lang):
|
8 |
# 输入文本
|
9 |
+
result=pipe(text,src_lang=src_lang ,tgt_lang=tgt_lang)
|
10 |
+
return result[0]["translation_text"]
|
|
|
|
|
|
|
|
|
11 |
|
12 |
text = gr.Textbox(lines=5,label="输入文本",placeholder="请输入文本")
|
13 |
src_lang = gr.Dropdown(label="源语言",choices=["afr_Latn",
|