Luis Sandoval commited on
Commit
8a59ccc
·
1 Parent(s): 7ec241c

feat: added gradio ui fro mt5 yoremnokki translator model

Browse files
Files changed (2) hide show
  1. app.py +34 -4
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,7 +1,37 @@
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, MT5ForConditionalGeneration
2
  import gradio as gr
3
 
4
+ model_name = "alfsnd/mt5-base-spanish-yoremnokki"
 
5
 
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+
8
+ model = MT5ForConditionalGeneration.from_pretrained(model_name)
9
+
10
+ def translate(input_text, src_lang, to_lang):
11
+ prompt = f"translate {src_lang} to {to_lang}: {input_text}"
12
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
13
+ outputs = model.generate(input_ids, max_new_tokens=1000)
14
+ model_translation = tokenizer.decode(outputs[0])
15
+ final_translation = model_translation[5:-4]
16
+ return final_translation
17
+
18
+ languages = [
19
+ 'Spanish', 'Yoremnokki'
20
+ ]
21
+
22
+ desc = "<h1>Traductor de Español a Yoremnokki utilizando un modelo de inteligecia artifical (alfsnd/mt5-base-spanish-yoremnokki)</h1>"
23
+
24
+ translator = gr.Interface(fn=translate,
25
+ inputs=[gr.Textbox(label="Traducir", placeholder="Introduzca su text"),
26
+ gr.Dropdown(label="From",
27
+ choices=languages,
28
+ value="Spanish",),
29
+ gr.Dropdown(label="To",
30
+ choices=languages,
31
+ value="Yoremnokki")],
32
+ outputs=gr.Textbox(label="Traducción"),
33
+ title="Traductor de Español a Yoremnokki",
34
+ description=desc
35
+ )
36
+
37
+ translator.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ sentencepiece
3
+ torch