import gradio as gr from transformers import pipeline def summarize(post): detector = pipeline( "text-classification", model="papluca/xlm-roberta-base-language-detection" ) lang_results = detector(post) if (detected_lang := lang_results[0]["label"]) == "en": summarizer_model_name = "sshleifer/distilbart-cnn-12-6" elif detected_lang == "es": summarizer_model_name = "ELiRF/mbart-large-cc25-dacsa-es" pipe = pipeline("summarization", model=summarizer_model_name) return pipe(post)[0]["summary_text"] iface = gr.Interface(fn=summarize, inputs="text", outputs="text") iface.launch()