Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,36 +2,31 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# 🔹
|
| 6 |
-
API_KEY = os.getenv("HF_API_KEY")
|
| 7 |
|
| 8 |
-
# 🔹 Cliente de
|
| 9 |
client = InferenceClient(
|
| 10 |
-
|
| 11 |
-
api_key=API_KEY #
|
| 12 |
)
|
| 13 |
|
| 14 |
-
# 🔒 Clave secreta de acceso
|
| 15 |
-
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 16 |
|
| 17 |
# 🔹 Función para reformular el texto
|
| 18 |
def reformular_texto(frase, clave):
|
| 19 |
if clave != SECRET_KEY:
|
| 20 |
return "🔴 Acceso denegado."
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
]
|
| 25 |
|
| 26 |
try:
|
| 27 |
-
completion = client.
|
| 28 |
-
|
| 29 |
-
messages=messages,
|
| 30 |
-
max_tokens=50,
|
| 31 |
-
)
|
| 32 |
-
return completion.choices[0].message.content # Devuelve el texto reformulado
|
| 33 |
except Exception as e:
|
| 34 |
-
return f"
|
| 35 |
|
| 36 |
# 🔹 Interfaz con Gradio
|
| 37 |
iface = gr.Interface(
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# 🔹 API Key de Hugging Face (debe estar en las Variables del Space)
|
| 6 |
+
API_KEY = os.getenv("HF_API_KEY")
|
| 7 |
|
| 8 |
+
# 🔹 Cliente de Hugging Face Inference
|
| 9 |
client = InferenceClient(
|
| 10 |
+
model="flax-community/spanish-t5-small",
|
| 11 |
+
api_key=API_KEY # Usa la API Key de Hugging Face
|
| 12 |
)
|
| 13 |
|
| 14 |
+
# 🔒 Clave secreta de acceso
|
| 15 |
+
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 16 |
|
| 17 |
# 🔹 Función para reformular el texto
|
| 18 |
def reformular_texto(frase, clave):
|
| 19 |
if clave != SECRET_KEY:
|
| 20 |
return "🔴 Acceso denegado."
|
| 21 |
|
| 22 |
+
# 🔥 Prompt mejorado
|
| 23 |
+
prompt = f"Convierte esta frase en español a una gramática correcta sin cambiar su significado: {frase}"
|
|
|
|
| 24 |
|
| 25 |
try:
|
| 26 |
+
completion = client.text_generation(prompt, max_new_tokens=50)
|
| 27 |
+
return completion
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
+
return f"⚠ Error en la inferencia: {str(e)}"
|
| 30 |
|
| 31 |
# 🔹 Interfaz con Gradio
|
| 32 |
iface = gr.Interface(
|