matheuscervantes55 commited on
Commit
1ce1b3e
1 Parent(s): 66f67f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
2
+ import gradio as gr
3
+
4
+ tokenizer = T5Tokenizer.from_pretrained("t5-large")
5
+ model = T5ForConditionalGeneration.from_pretrained("t5-large")
6
+
7
+ def translate_text(input_text, source_lang, target_lang):
8
+ """Translates text using the T5 model."""
9
+ prefix = f"translate {source_lang} to {target_lang}: "
10
+ input_ids = tokenizer(prefix + input_text, return_tensors="pt").input_ids
11
+ outputs = model.generate(input_ids, max_new_tokens=128)
12
+ translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return translated_text
14
+
15
+ iface = gr.Interface(
16
+ fn=translate_text,
17
+ inputs=[
18
+ gr.Textbox(lines=2, placeholder="Digite o texto aqui...", label="Texto de Entrada"),
19
+ gr.Dropdown(["English", "French", "German"], label="Idioma de Origem"),
20
+ gr.Dropdown(["English", "French", "German"], label="Idioma de Destino"),
21
+ ],
22
+ outputs="text",
23
+ title="Aplicativo de Tradução T5",
24
+ description="Este aplicativo usa o modelo T5 para traduzir texto entre idiomas.",
25
+ )
26
+ iface.launch(share=True)