Update app.py
Browse files
app.py
CHANGED
@@ -4,35 +4,35 @@ import torch
|
|
4 |
import os
|
5 |
from huggingface_hub import login
|
6 |
|
7 |
-
#
|
8 |
hf_token = os.environ["HF_TOKEN"]
|
9 |
login(token=hf_token)
|
10 |
|
11 |
-
#
|
12 |
device = 0 if torch.cuda.is_available() else -1
|
13 |
|
14 |
-
#
|
15 |
pipe = pipeline(
|
16 |
"text-generation",
|
17 |
-
model="openchat/openchat-3.5-1210"
|
18 |
device=device
|
19 |
)
|
20 |
|
21 |
-
# Función de respuesta
|
22 |
def responder(prompt):
|
23 |
respuesta = pipe(
|
24 |
prompt,
|
25 |
-
max_new_tokens=
|
26 |
do_sample=True,
|
27 |
-
temperature=0.8,
|
28 |
top_k=50,
|
29 |
top_p=0.9
|
30 |
-
)[0][
|
31 |
return respuesta
|
32 |
|
33 |
-
# Interfaz Gradio
|
34 |
with gr.Blocks() as demo:
|
35 |
-
gr.Markdown("## ⚡ AmInside 1.0\
|
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)
|