Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
-
MODEL_NAME,
|
| 12 |
-
torch_dtype=torch.float16,
|
| 13 |
-
device_map="auto"
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# 馃敀 Clave secreta para evitar uso no autorizado
|
| 17 |
-
SECRET_KEY = "MI_CLAVE_SUPER_SECRETA"
|
| 18 |
-
|
| 19 |
-
# 馃敼 Funci贸n para reformular frases
|
| 20 |
-
def reformular_texto(frase, clave):
|
| 21 |
-
if clave != SECRET_KEY:
|
| 22 |
-
return "馃敶 Acceso denegado."
|
| 23 |
-
|
| 24 |
-
prompt = f"Reescribe esta frase con mejor gram谩tica en espa帽ol: {frase}"
|
| 25 |
-
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, padding=True).to(model.device)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=reformular_texto,
|
| 35 |
-
inputs=
|
| 36 |
outputs="text",
|
| 37 |
-
title="
|
| 38 |
-
description="
|
| 39 |
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
# 馃攽 Cargar API Key desde las variables de entorno
|
| 6 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
| 7 |
|
| 8 |
+
# 馃寪 Cliente de la API
|
| 9 |
+
client = InferenceClient(model="bigscience/bloomz-560m", token=HF_API_KEY)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# 馃幆 Funci贸n de reformulaci贸n
|
| 12 |
+
def reformular_texto(frase):
|
| 13 |
+
prompt = f"Reescribe esta frase en espa帽ol con buena gram谩tica: {frase}"
|
| 14 |
+
respuesta = client.text_generation(prompt, max_new_tokens=50)
|
| 15 |
+
return respuesta.strip()
|
| 16 |
|
| 17 |
+
# 馃殌 Interfaz en Hugging Face Space
|
| 18 |
iface = gr.Interface(
|
| 19 |
fn=reformular_texto,
|
| 20 |
+
inputs="text",
|
| 21 |
outputs="text",
|
| 22 |
+
title="Prueba de Reformulaci贸n en HF",
|
| 23 |
+
description="Convierte frases primitivas a frases bien estructuradas."
|
| 24 |
)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|