Hodely commited on
Commit
e6b3aea
·
verified ·
1 Parent(s): 136133a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -4,35 +4,31 @@ import torch
4
  import os
5
  from huggingface_hub import login
6
 
7
- # Autenticación Hugging Face
8
  hf_token = os.environ["HF_TOKEN"]
9
  login(token=hf_token)
10
 
11
- # Selección de dispositivo
12
  device = 0 if torch.cuda.is_available() else -1
13
 
14
- # Carga de modelo instruct/chat funcional
15
  pipe = pipeline(
16
  "text-generation",
17
- model="openchat/openchat-3.5-1210", # <- modelo instruct real
18
  device=device
19
  )
20
 
21
- # Función de respuesta rápida y fluida
22
  def responder(prompt):
 
23
  respuesta = pipe(
24
- prompt,
25
- max_new_tokens=60,
26
  do_sample=True,
27
- temperature=0.8,
28
  top_k=50,
29
  top_p=0.9
30
- )[0]["generated_text"]
31
- return respuesta
32
 
33
- # Interfaz Gradio
34
  with gr.Blocks() as demo:
35
- gr.Markdown("## AmInside 1.0\nAsistente IA rápido y con cerebro 🧠")
36
  entrada = gr.Textbox(label="Escribe tu mensaje")
37
  salida = gr.Textbox(label="Respuesta")
38
  entrada.submit(fn=responder, inputs=entrada, outputs=salida)
 
4
  import os
5
  from huggingface_hub import login
6
 
 
7
  hf_token = os.environ["HF_TOKEN"]
8
  login(token=hf_token)
9
 
 
10
  device = 0 if torch.cuda.is_available() else -1
11
 
 
12
  pipe = pipeline(
13
  "text-generation",
14
+ model="HuggingFaceH4/zephyr-1.3b",
15
  device=device
16
  )
17
 
 
18
  def responder(prompt):
19
+ formatted_prompt = f"<|system|>You are a helpful assistant.<|user|>{prompt}<|assistant|>"
20
  respuesta = pipe(
21
+ formatted_prompt,
22
+ max_new_tokens=100,
23
  do_sample=True,
24
+ temperature=0.7,
25
  top_k=50,
26
  top_p=0.9
27
+ )[0]['generated_text']
28
+ return respuesta.replace(formatted_prompt, "").strip()
29
 
 
30
  with gr.Blocks() as demo:
31
+ gr.Markdown("## 🤖 AmInside 1.0 versión ligera y educada")
32
  entrada = gr.Textbox(label="Escribe tu mensaje")
33
  salida = gr.Textbox(label="Respuesta")
34
  entrada.submit(fn=responder, inputs=entrada, outputs=salida)