JimmyK300 commited on
Commit
bfe2b89
·
verified ·
1 Parent(s): c310b3b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load model and tokenizer
5
+ model_name = "VietAI/envit5-translation"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
+
9
+ # Translation function
10
+ def translate(text):
11
+ input_ids = tokenizer(text, return_tensors="pt", padding=True).input_ids
12
+ output_ids = model.generate(input_ids, max_length=512)
13
+ return tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
14
+
15
+ # Gradio interface
16
+ demo = gr.Interface(
17
+ fn=translate,
18
+ inputs="text",
19
+ outputs="text",
20
+ title="Vietnamese-English Translation",
21
+ description="Translate text between English and Vietnamese using the VietAI envit5 model."
22
+ )
23
+
24
+ # Launch the Gradio app
25
+ demo.launch(debug=True)