Spaces:
Sleeping
Sleeping
| 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() |