Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,24 @@ 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():
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
10 |
-
tokenizer.pad_token = tokenizer.eos_token
|
11 |
|
12 |
if "model" not in globals():
|
13 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
|
14 |
-
model.eval()
|
15 |
|
16 |
-
# Funci贸n de humanizaci贸n
|
17 |
def humanize_text(input_text):
|
18 |
system_prompt = (
|
19 |
-
"Reescribe el siguiente texto de manera m谩s
|
20 |
-
"
|
21 |
-
"
|
22 |
-
"Evita
|
23 |
-
"Aqu铆 tienes un ejemplo de c贸mo deber铆a sonar la reescritura:\n\n"
|
24 |
-
"Ejemplo:\n"
|
25 |
-
"Texto original: 'Nuestro software es la mejor opci贸n para cualquier empresa.'\n"
|
26 |
-
"Texto humanizado: 'Si buscas una herramienta que realmente optimice tu negocio, nuestro software puede ser justo lo que necesitas.'\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 demasiado cortas
|
39 |
-
do_sample=True, # 馃敼
|
40 |
-
temperature=0.
|
41 |
top_p=0.9, # 馃敼 Mantiene coherencia en la reescritura
|
42 |
-
repetition_penalty=1.05, # 馃敼 Evita repeticiones sin
|
43 |
num_return_sequences=1, # 馃敼 Genera 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 m谩s estable que funcion贸 bien en pruebas anteriores
|
6 |
model_name = "BSC-LT/salamandra-2b"
|
7 |
|
8 |
if "tokenizer" not in globals():
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
10 |
+
tokenizer.pad_token = tokenizer.eos_token
|
11 |
|
12 |
if "model" 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 mejor ajuste probado
|
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, # 馃敼 Evita repeticiones sin afectar fluidez
|
38 |
num_return_sequences=1, # 馃敼 Genera 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)")
|
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")
|