Spaces:
Running
Running
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,13 +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
|
17 |
def humanize_text(input_text):
|
18 |
system_prompt = (
|
19 |
-
"Reescribe el siguiente texto
|
20 |
-
"
|
21 |
-
"
|
22 |
-
"Evita
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
|
25 |
prompt = f"{system_prompt}\n\nTexto original: {input_text}\n\nTexto humanizado:"
|
@@ -29,12 +33,12 @@ def humanize_text(input_text):
|
|
29 |
outputs = model.generate(
|
30 |
inputs.input_ids,
|
31 |
attention_mask=inputs.attention_mask,
|
32 |
-
max_new_tokens=
|
33 |
-
min_length=50, # 馃敼 Evita respuestas
|
34 |
-
do_sample=True, # 馃敼
|
35 |
-
temperature=0.
|
36 |
-
top_p=0.
|
37 |
-
repetition_penalty=1.
|
38 |
num_return_sequences=1, # 馃敼 Solo una respuesta bien formulada
|
39 |
)
|
40 |
|
@@ -42,7 +46,7 @@ def humanize_text(input_text):
|
|
42 |
|
43 |
# Interfaz en Gradio
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.Markdown("# 鉁嶏笍 Humanizaci贸n de Texto con ALIA (
|
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")
|
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
4 |
|
5 |
+
# Cargar el modelo m谩s 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 la humanizaci贸n
|
17 |
def humanize_text(input_text):
|
18 |
system_prompt = (
|
19 |
+
"Reescribe el siguiente texto con un estilo m谩s natural y conversacional, "
|
20 |
+
"como si fuera escrito por una persona real. Reformula frases r铆gidas para "
|
21 |
+
"hacerlas m谩s din谩micas, sin cambiar el significado ni omitir informaci贸n clave. "
|
22 |
+
"Evita redundancias y usa un lenguaje m谩s fluido y moderno.\n\n"
|
23 |
+
"**Ejemplo de reescritura:**\n"
|
24 |
+
"**Texto original:** 'Se informa a los usuarios que el acceso al sistema debe realizarse antes de la fecha l铆mite.'\n"
|
25 |
+
"**Texto humanizado:** 'Recuerda acceder al sistema antes de la fecha l铆mite para evitar problemas.'\n\n"
|
26 |
+
"Ahora reescribe el siguiente texto:"
|
27 |
)
|
28 |
|
29 |
prompt = f"{system_prompt}\n\nTexto original: {input_text}\n\nTexto humanizado:"
|
|
|
33 |
outputs = model.generate(
|
34 |
inputs.input_ids,
|
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, # 馃敼 Mayor variabilidad en respuestas
|
39 |
+
temperature=0.85, # 馃敼 Aumentamos creatividad para forzar reformulaci贸n
|
40 |
+
top_p=0.92, # 馃敼 Mayor probabilidad de palabras m谩s naturales
|
41 |
+
repetition_penalty=1.08, # 馃敼 Evita respuestas repetitivas
|
42 |
num_return_sequences=1, # 馃敼 Solo una respuesta bien formulada
|
43 |
)
|
44 |
|
|
|
46 |
|
47 |
# Interfaz en Gradio
|
48 |
with gr.Blocks() as demo:
|
49 |
+
gr.Markdown("# 鉁嶏笍 Humanizaci贸n de Texto con ALIA (Forzando Reformulaci贸n)")
|
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")
|