Spaces:
Sleeping
Sleeping
File size: 1,264 Bytes
c082f1c cb6fa70 af55ba7 c082f1c cb6fa70 c082f1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import gradio as gr
from transformers import pipeline
traductor = pipeline(task='text2text-generation', model='facebook/m2m100_418M')
def tradrucir(text,toLan):
response= traductor(text, forced_bos_token_id=traductor.tokenizer.get_lang_id(lang=toLan))
return response[0]["generated_text"]
def fun1(input_text): return tradrucir(input_text,"en")
def fun2(input_text): return tradrucir(input_text,"es")
def clear_input(input_text):
# Limpia el input
return ""
with gr.Blocks(css="""
.gr-button {
background-color: green;
color: white;
}
.gr-textbox {
display: inline-block;
width: 48%;
margin-right: 4%;
}
.gr-textbox:last-child {
margin-right: 0;
}
""") as demo:
with gr.Row():
input_text = gr.Textbox(label="Input")
response_label = gr.Textbox(label="Respuesta")
with gr.Row():
clear_btn = gr.Button("Clear")
btn1 = gr.Button("Español a Inglés")
btn2 = gr.Button("Inglés a Español")
clear_btn.click(fn=clear_input, inputs=input_text, outputs=input_text)
btn1.click(fn=fun1, inputs=input_text, outputs=response_label)
btn2.click(fn=fun2, inputs=input_text, outputs=response_label)
demo.launch() |