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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -4,35 +4,35 @@ import torch
4
  import os
5
  from huggingface_hub import login
6
 
7
- # Inicia sesión en Hugging Face con tu token
8
  hf_token = os.environ["HF_TOKEN"]
9
  login(token=hf_token)
10
 
11
- # Usa GPU si está disponible
12
  device = 0 if torch.cuda.is_available() else -1
13
 
14
- # Modelo ligero y público (rápido en CPU también)
15
  pipe = pipeline(
16
  "text-generation",
17
- model="openchat/openchat-3.5-1210"
18
  device=device
19
  )
20
 
21
- # Función de respuesta optimizada
22
  def responder(prompt):
23
  respuesta = pipe(
24
  prompt,
25
- max_new_tokens=40, # menos tokens = más velocidad
26
  do_sample=True,
27
- temperature=0.8, # más creatividad
28
  top_k=50,
29
  top_p=0.9
30
- )[0]['generated_text']
31
  return respuesta
32
 
33
- # Interfaz Gradio optimizada
34
  with gr.Blocks() as demo:
35
- gr.Markdown("## ⚡ AmInside 1.0\nTu asistente IA rápido y gratuito")
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
+ # 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)