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 estable
|
| 6 |
model_name = "BSC-LT/salamandra-2b"
|
| 7 |
|
| 8 |
if "tokenizer" not in globals():
|
|
@@ -13,18 +13,13 @@ if "model" not in globals():
|
|
| 13 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
|
| 14 |
model.eval()
|
| 15 |
|
| 16 |
-
# 馃敼 Funci贸n
|
| 17 |
def humanize_text(input_text):
|
| 18 |
system_prompt = (
|
| 19 |
-
"Reescribe el siguiente texto de manera m谩s natural y
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 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 |
|
| 30 |
prompt = f"{system_prompt}\n\nTexto original: {input_text}\n\nTexto humanizado:"
|
|
@@ -34,12 +29,12 @@ def humanize_text(input_text):
|
|
| 34 |
outputs = model.generate(
|
| 35 |
inputs.input_ids,
|
| 36 |
attention_mask=inputs.attention_mask,
|
| 37 |
-
max_new_tokens=
|
| 38 |
-
min_length=50, # 馃敼 Evita respuestas cortas
|
| 39 |
-
do_sample=True, # 馃敼 Mantiene variabilidad
|
| 40 |
-
temperature=0.
|
| 41 |
-
top_p=0.
|
| 42 |
-
repetition_penalty=1.
|
| 43 |
num_return_sequences=1, # 馃敼 Solo una respuesta bien formulada
|
| 44 |
)
|
| 45 |
|
|
@@ -47,7 +42,7 @@ def humanize_text(input_text):
|
|
| 47 |
|
| 48 |
# Interfaz en Gradio
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
-
gr.Markdown("# 鉁嶏笍 Humanizaci贸n de Texto con ALIA (
|
| 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")
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Cargar el modelo estable que mejor funcion贸
|
| 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 de humanizaci贸n con el prompt m谩s efectivo
|
| 17 |
def humanize_text(input_text):
|
| 18 |
system_prompt = (
|
| 19 |
+
"Reescribe el siguiente texto de manera m谩s clara, natural y atractiva, "
|
| 20 |
+
"sin cambiar su significado. Reformula frases r铆gidas y estructuradas para "
|
| 21 |
+
"que sean m谩s fluidas y conversacionales, pero sin perder precisi贸n. "
|
| 22 |
+
"Evita tecnicismos y burocracia innecesaria."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
prompt = f"{system_prompt}\n\nTexto original: {input_text}\n\nTexto humanizado:"
|
|
|
|
| 29 |
outputs = model.generate(
|
| 30 |
inputs.input_ids,
|
| 31 |
attention_mask=inputs.attention_mask,
|
| 32 |
+
max_new_tokens=130, # 馃敼 Equilibrio entre reformulaci贸n y velocidad
|
| 33 |
+
min_length=50, # 馃敼 Evita respuestas demasiado cortas
|
| 34 |
+
do_sample=True, # 馃敼 Mantiene variabilidad sin ralentizar
|
| 35 |
+
temperature=0.75, # 馃敼 Buen balance entre creatividad y rapidez
|
| 36 |
+
top_p=0.9, # 馃敼 Mantiene coherencia en la reescritura
|
| 37 |
+
repetition_penalty=1.05, # 馃敼 Reduce repeticiones sin afectar fluidez
|
| 38 |
num_return_sequences=1, # 馃敼 Solo una respuesta bien formulada
|
| 39 |
)
|
| 40 |
|
|
|
|
| 42 |
|
| 43 |
# Interfaz en Gradio
|
| 44 |
with gr.Blocks() as demo:
|
| 45 |
+
gr.Markdown("# 鉁嶏笍 Humanizaci贸n de Texto con ALIA (Versi贸n 脫ptima Restaurada)")
|
| 46 |
input_text = gr.Textbox(label="Pega aqu铆 el texto generado por IA para humanizar")
|
| 47 |
output_text = gr.Textbox(label="Texto humanizado por ALIA", interactive=False)
|
| 48 |
submit_button = gr.Button("Humanizar Texto")
|