alvibe75 commited on
Commit
711743e
verified
1 Parent(s): 66d6d62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -30
app.py CHANGED
@@ -1,41 +1,26 @@
1
  import gradio as gr
2
- import torch
3
- from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
- # 馃敼 Modelo seleccionado
6
- MODEL_NAME = "EleutherAI/gpt-neo-2.7B"
7
 
8
- # 馃敼 Cargar modelo y tokenizador con soporte para `accelerate`
9
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
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
- with torch.no_grad():
28
- outputs = model.generate(inputs.input_ids, max_length=50, temperature=0.7, top_k=50)
29
-
30
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
 
31
 
32
- # 馃敼 Interfaz con Gradio
33
  iface = gr.Interface(
34
  fn=reformular_texto,
35
- inputs=[gr.Textbox(label="Texto a reformular"), gr.Textbox(label="Clave de acceso", type="password")],
36
  outputs="text",
37
- title="Reformulador de Texto en Espa帽ol",
38
- description="Este modelo reformula frases en espa帽ol con mejor gram谩tica."
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__":