danfexr99 commited on
Commit
af4ec9d
1 Parent(s): 0c16717

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import pipeline
4
+ pipe = pipeline(task='text2text-generation', model='facebook/m2m100_418M')
5
+
6
+
7
+ def submit_action(input_text, radio_choice):
8
+ language = "en"
9
+ if(radio_choice=="Español"):
10
+ language= "es"
11
+ elif(radio_choice=="Ingles"):
12
+ language= "en"
13
+ print(f"Language: {language}")
14
+ traduccion = pipe(input_text, forced_bos_token_id=pipe.tokenizer.get_lang_id(lang=language))
15
+
16
+ return traduccion[0]["generated_text"]
17
+
18
+
19
+
20
+ with gr.Blocks() as demo:
21
+ text = gr.Textbox(label="Texto a traducir")
22
+ traducido = gr.Textbox(label="Texto traducido")
23
+ radio_choice = gr.Radio(choices=["Español", "Ingles"], value="Ingles", label="Opciones")
24
+
25
+ submit_btn = gr.Button("Submit")
26
+ clear_btn = gr.ClearButton(components=[text, radio_choice])
27
+
28
+ with gr.Row():
29
+ radio_choice.select(fn=lambda value: print(f"Radio value: {value.value}"))
30
+
31
+ submit_btn.click(fn=submit_action, inputs=[text, radio_choice], outputs=traducido)
32
+
33
+ demo.launch()