Update app.py
Browse files
app.py
CHANGED
|
@@ -8,11 +8,16 @@ model_name = "Helsinki-NLP/opus-mt-en-es"
|
|
| 8 |
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
| 9 |
model = MarianMTModel.from_pretrained(model_name)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def traducir(texto):
|
| 12 |
texto_unido = ""
|
| 13 |
texto_completo = ""
|
| 14 |
-
text_summarized = summarizer(texto, max_length=1000, min_length=30, do_sample=False)
|
| 15 |
-
texto_solo = ">>esp<< " + text_summarized[0]["summary_text"]
|
| 16 |
texto_separado = texto.split(" ")
|
| 17 |
for i in range(len(texto_separado)):
|
| 18 |
texto_unido = texto_unido + "".join(texto_separado[i]) + " "
|
|
@@ -21,16 +26,16 @@ def traducir(texto):
|
|
| 21 |
texto_unido = [tokenizer.decode(t, skip_special_tokens=True) for t in texto_unido_traducido]
|
| 22 |
texto_completo = texto_completo + "".join(texto_unido[0]) + " "
|
| 23 |
texto_unido = ""
|
| 24 |
-
|
| 25 |
-
texto_resumido = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_resumido]
|
| 26 |
-
return texto_resumido[0], texto_completo
|
| 27 |
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
text = gr.Textbox(label="Introduzca el texto a resumir y traducir")
|
| 30 |
-
output1 = gr.Textbox(label="Texto resumido
|
| 31 |
-
output2 = gr.Textbox(label="Texto completo
|
| 32 |
sumbtn = gr.Button("Resumir y traducir")
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
# demo = gr.Interface(
|
| 35 |
# fn=traducir,
|
| 36 |
# inputs=[gr.Textbox(label="Texto")],
|
|
|
|
| 8 |
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
| 9 |
model = MarianMTModel.from_pretrained(model_name)
|
| 10 |
|
| 11 |
+
def traducir_resumir(texto):
|
| 12 |
+
text_summarized = summarizer(texto, max_length=1000, min_length=30, do_sample=False)
|
| 13 |
+
texto_solo = ">>esp<< " + text_summarized[0]["summary_text"]
|
| 14 |
+
translated_resumido = model.generate(**tokenizer(texto_solo, return_tensors="pt", padding=True))
|
| 15 |
+
texto_resumido = [tokenizer.decode(t, skip_special_tokens=True) for t in translated_resumido]
|
| 16 |
+
return texto_resumido[0]
|
| 17 |
+
|
| 18 |
def traducir(texto):
|
| 19 |
texto_unido = ""
|
| 20 |
texto_completo = ""
|
|
|
|
|
|
|
| 21 |
texto_separado = texto.split(" ")
|
| 22 |
for i in range(len(texto_separado)):
|
| 23 |
texto_unido = texto_unido + "".join(texto_separado[i]) + " "
|
|
|
|
| 26 |
texto_unido = [tokenizer.decode(t, skip_special_tokens=True) for t in texto_unido_traducido]
|
| 27 |
texto_completo = texto_completo + "".join(texto_unido[0]) + " "
|
| 28 |
texto_unido = ""
|
| 29 |
+
return texto_completo
|
|
|
|
|
|
|
| 30 |
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
text = gr.Textbox(label="Introduzca el texto a resumir y traducir")
|
| 33 |
+
output1 = gr.Textbox(label="Texto resumido traducido")
|
| 34 |
+
output2 = gr.Textbox(label="Texto completo traducido")
|
| 35 |
sumbtn = gr.Button("Resumir y traducir")
|
| 36 |
+
tradbtn = gr.Button("Traducir texto")
|
| 37 |
+
sumbtn.click(fn = traducir_resumir, inputs = text, outputs = output1)
|
| 38 |
+
tradbtn.click(fn = traducir, inputs = text, outputs = output2)
|
| 39 |
# demo = gr.Interface(
|
| 40 |
# fn=traducir,
|
| 41 |
# inputs=[gr.Textbox(label="Texto")],
|