|
from transformers import pipeline, MarianMTModel, MarianTokenizer |
|
import gradio as gr |
|
|
|
summarizer = pipeline("summarization", model="Falconsai/text_summarization") |
|
|
|
|
|
model_name = "Helsinki-NLP/opus-mt-en-es" |
|
tokenizer = MarianTokenizer.from_pretrained(model_name) |
|
model = MarianMTModel.from_pretrained(model_name) |
|
|
|
def traducir(texto): |
|
text_summarized = summarizer(texto, max_length=1000, min_length=30, do_sample=False) |
|
texto_solo = ">>esp<< " + text_summarized[0]["summary_text"] |
|
translated_entero = model.generate(**tokenizer(texto, return_tensors="pt", padding=True)) |
|
texto_entero = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_entero] |
|
translated_resumido = model.generate(**tokenizer(texto_solo, return_tensors="pt", padding=True)) |
|
texto_resumido = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_resumido] |
|
return texto_resumido[0], texto_entero[0], |
|
|
|
demo = gr.Interface( |
|
fn=traducir, |
|
inputs=["text"], |
|
outputs=["text", "text"], |
|
) |
|
|
|
demo.launch() |
|
|