Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer,
|
| 3 |
|
| 4 |
-
# 🔹
|
| 5 |
-
MODEL_NAME = "
|
| 6 |
|
| 7 |
# 🔹 Cargar el modelo y el tokenizador
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
-
model =
|
| 10 |
|
| 11 |
-
# 🔒 Clave secreta
|
| 12 |
-
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 13 |
|
| 14 |
-
# 🔹 Función para
|
| 15 |
-
def
|
| 16 |
if clave != SECRET_KEY:
|
| 17 |
return "🔴 Acceso denegado."
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 23 |
|
| 24 |
# 🔹 Interfaz con Gradio
|
| 25 |
iface = gr.Interface(
|
| 26 |
-
fn=
|
| 27 |
-
inputs=[gr.Textbox(label="Texto a
|
| 28 |
outputs="text",
|
| 29 |
-
title="
|
| 30 |
-
description="Este modelo
|
| 31 |
)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
+
# 🔹 Usamos un modelo T5 en español mejor adaptado a generación de texto
|
| 5 |
+
MODEL_NAME = "mrm8488/t5-base-spanish-text-to-text"
|
| 6 |
|
| 7 |
# 🔹 Cargar el modelo y el tokenizador
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 10 |
|
| 11 |
+
# 🔒 Clave secreta
|
| 12 |
+
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 13 |
|
| 14 |
+
# 🔹 Función para reformular texto con mejor NLP
|
| 15 |
+
def reformular_texto(frase, clave):
|
| 16 |
if clave != SECRET_KEY:
|
| 17 |
return "🔴 Acceso denegado."
|
| 18 |
+
|
| 19 |
+
# 🔥 PROMPT INTELIGENTE para reformulación correcta
|
| 20 |
+
prompt = f"Corrige la siguiente oración usando gramática correcta y una estructura natural en español: {frase}"
|
| 21 |
+
|
| 22 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True)
|
| 23 |
+
outputs = model.generate(**inputs, max_length=50)
|
| 24 |
+
|
| 25 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 26 |
|
| 27 |
# 🔹 Interfaz con Gradio
|
| 28 |
iface = gr.Interface(
|
| 29 |
+
fn=reformular_texto,
|
| 30 |
+
inputs=[gr.Textbox(label="Texto a reformular"), gr.Textbox(label="Clave de acceso", type="password")],
|
| 31 |
outputs="text",
|
| 32 |
+
title="Reformulador de Texto en Español",
|
| 33 |
+
description="Este modelo reformula frases en español con gramática correcta."
|
| 34 |
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|