Spaces:
Paused
Paused
File size: 2,461 Bytes
6c036c1 aab52b9 b08158b a9b1392 aab52b9 b08158b 61e43c4 b08158b 19693ec 4025a2e b08158b 5ef6d7c 4025a2e 5ef6d7c e3d3bd5 b08158b 19693ec b08158b 4025a2e b08158b 4025a2e b08158b 4025a2e b08158b 19693ec aab52b9 19693ec aab52b9 4025a2e b08158b aab52b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Cargar el modelo y el tokenizador solo una vez para evitar recargas
model_name = "BSC-LT/salamandra-2b"
if "tokenizer" not in globals():
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token # 馃敼 Evita errores de atenci贸n
if "model" not in globals():
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
model.eval() # 馃敼 Optimiza la inferencia para que sea m谩s r谩pida
# Funci贸n exclusiva para humanizaci贸n de texto con enfoque en marketing
def humanize_text(input_text):
system_prompt = (
"Reescribe el siguiente texto con un tono m谩s natural, conversacional y cercano, ideal para marketing. "
"Haz que fluya de manera m谩s atractiva y persuasiva, como si lo escribiera un experto en marketing, "
"pero sin modificar ni inventar datos. Mant茅n toda la informaci贸n original sin omitir detalles. "
"Puedes reorganizar las oraciones para mejorar la claridad y el impacto. "
"Aseg煤rate de que el resultado se sienta humano y aut茅ntico, evitando cualquier indicio de automatizaci贸n."
)
prompt = f"{system_prompt}\n\nTexto original: {input_text}\n\nTexto humanizado:"
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True)
outputs = model.generate(
inputs.input_ids,
attention_mask=inputs.attention_mask,
max_new_tokens=150, # 馃敼 Suficiente espacio para reformular el texto sin cortes
do_sample=True, # 馃敼 Mantiene variabilidad en la reescritura
temperature=0.8, # 馃敼 Permite m谩s fluidez sin inventar datos
top_p=0.9, # 馃敼 Mantiene coherencia en la reescritura
repetition_penalty=1.1, # 馃敼 Evita repeticiones innecesarias
early_stopping=True,
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Interfaz en Gradio
with gr.Blocks() as demo:
gr.Markdown("# 鉁嶏笍 Humanizaci贸n de Texto con ALIA (Optimizado para Marketing)")
input_text = gr.Textbox(label="Pega aqu铆 el texto generado por IA para humanizar")
output_text = gr.Textbox(label="Texto humanizado por ALIA", interactive=False)
submit_button = gr.Button("Humanizar Texto")
submit_button.click(humanize_text, inputs=input_text, outputs=output_text)
demo.launch()
|