Proyecto1 / app.py
Horchatas's picture
Create app.py
0a087dc verified
raw
history blame
1.13 kB
from transformers import pipeline, MarianMTModel, MarianTokenizer
import gradio as gr
summarizer = pipeline("summarization", model="Falconsai/text_summarization") # modelo de resumen de texto inglés a inglés
# modelo para la traducción del texto ingles a español
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()