import gradio as gr from transformers import pipeline pipe = pipeline(task='text2text-generation', model='facebook/m2m100_418M') def submit_action(input_text, radio_choice): language = "en" if(radio_choice=="Español"): language= "es" elif(radio_choice=="Ingles"): language= "en" print(f"Language: {language}") traduccion = pipe(input_text, forced_bos_token_id=pipe.tokenizer.get_lang_id(lang=language)) return traduccion[0]["generated_text"] with gr.Blocks() as demo: text = gr.Textbox(label="Texto a traducir") traducido = gr.Textbox(label="Texto traducido") radio_choice = gr.Radio(choices=["Español", "Ingles"], value="Ingles", label="Opciones") submit_btn = gr.Button("Submit") clear_btn = gr.ClearButton(components=[text, radio_choice]) with gr.Row(): radio_choice.select(fn=lambda value: print(f"Radio value: {value.value}")) submit_btn.click(fn=submit_action, inputs=[text, radio_choice], outputs=traducido) demo.launch()