File size: 637 Bytes
cac43d6
81ddc22
cac43d6
 
81ddc22
 
 
 
 
 
3d2b507
81ddc22
 
 
 
 
 
 
cac43d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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()