Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Cargar el modelo
|
| 6 |
model_name = "BSC-LT/salamandra-2b"
|
| 7 |
|
| 8 |
if "tokenizer" not in globals():
|
|
@@ -13,16 +13,17 @@ if "model" not in globals():
|
|
| 13 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
|
| 14 |
model.eval()
|
| 15 |
|
| 16 |
-
# 🔹 Función optimizada para forzar
|
| 17 |
def humanize_text(input_text):
|
| 18 |
system_prompt = (
|
| 19 |
-
"Reescribe el siguiente texto
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"Evita redundancias y usa un lenguaje más fluido y moderno.\n\n"
|
| 23 |
"**Ejemplo de reescritura:**\n"
|
| 24 |
-
"**Texto original:** '
|
| 25 |
-
"**Texto humanizado:** '
|
|
|
|
|
|
|
| 26 |
"Ahora reescribe el siguiente texto:"
|
| 27 |
)
|
| 28 |
|
|
@@ -35,10 +36,10 @@ def humanize_text(input_text):
|
|
| 35 |
attention_mask=inputs.attention_mask,
|
| 36 |
max_new_tokens=140, # 🔹 Balance entre reformulación y velocidad
|
| 37 |
min_length=50, # 🔹 Evita respuestas cortas
|
| 38 |
-
do_sample=True, # 🔹
|
| 39 |
-
temperature=0.
|
| 40 |
-
top_p=0.
|
| 41 |
-
repetition_penalty=1.
|
| 42 |
num_return_sequences=1, # 🔹 Solo una respuesta bien formulada
|
| 43 |
)
|
| 44 |
|
|
@@ -46,7 +47,7 @@ def humanize_text(input_text):
|
|
| 46 |
|
| 47 |
# Interfaz en Gradio
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
-
gr.Markdown("# ✍️ Humanización de Texto con ALIA (
|
| 50 |
input_text = gr.Textbox(label="Pega aquí el texto generado por IA para humanizar")
|
| 51 |
output_text = gr.Textbox(label="Texto humanizado por ALIA", interactive=False)
|
| 52 |
submit_button = gr.Button("Humanizar Texto")
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Cargar el modelo estable
|
| 6 |
model_name = "BSC-LT/salamandra-2b"
|
| 7 |
|
| 8 |
if "tokenizer" not in globals():
|
|
|
|
| 13 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
|
| 14 |
model.eval()
|
| 15 |
|
| 16 |
+
# 🔹 Función optimizada para forzar un tono más natural
|
| 17 |
def humanize_text(input_text):
|
| 18 |
system_prompt = (
|
| 19 |
+
"Reescribe el siguiente texto de manera más natural y conversacional, como si estuvieras explicándoselo a un amigo. "
|
| 20 |
+
"Evita palabras complejas innecesarias y haz que fluya mejor, sin cambiar su significado. "
|
| 21 |
+
"Hazlo más atractivo y fácil de leer.\n\n"
|
|
|
|
| 22 |
"**Ejemplo de reescritura:**\n"
|
| 23 |
+
"**Texto original:** 'La organización ha optimizado sus procesos para maximizar la eficiencia.'\n"
|
| 24 |
+
"**Texto humanizado:** 'Ahora la organización trabaja de manera más eficiente gracias a procesos optimizados.'\n\n"
|
| 25 |
+
"**Texto original:** 'Se requiere el acceso al sistema antes de la fecha límite establecida.'\n"
|
| 26 |
+
"**Texto humanizado:** 'Asegúrate de ingresar al sistema antes de la fecha límite para evitar problemas.'\n\n"
|
| 27 |
"Ahora reescribe el siguiente texto:"
|
| 28 |
)
|
| 29 |
|
|
|
|
| 36 |
attention_mask=inputs.attention_mask,
|
| 37 |
max_new_tokens=140, # 🔹 Balance entre reformulación y velocidad
|
| 38 |
min_length=50, # 🔹 Evita respuestas cortas
|
| 39 |
+
do_sample=True, # 🔹 Mantiene variabilidad en respuestas
|
| 40 |
+
temperature=0.9, # 🔹 Aumentamos creatividad para forzar reformulación
|
| 41 |
+
top_p=0.95, # 🔹 Permite opciones más variadas
|
| 42 |
+
repetition_penalty=1.02, # 🔹 Evita que repita estructuras del texto original
|
| 43 |
num_return_sequences=1, # 🔹 Solo una respuesta bien formulada
|
| 44 |
)
|
| 45 |
|
|
|
|
| 47 |
|
| 48 |
# Interfaz en Gradio
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
+
gr.Markdown("# ✍️ Humanización de Texto con ALIA (Tono más natural)")
|
| 51 |
input_text = gr.Textbox(label="Pega aquí el texto generado por IA para humanizar")
|
| 52 |
output_text = gr.Textbox(label="Texto humanizado por ALIA", interactive=False)
|
| 53 |
submit_button = gr.Button("Humanizar Texto")
|