Update app.py
Browse files
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="
|
18 |
device=device
|
19 |
)
|
20 |
|
21 |
-
# Función de respuesta rápida y fluida
|
22 |
def responder(prompt):
|
|
|
23 |
respuesta = pipe(
|
24 |
-
|
25 |
-
max_new_tokens=
|
26 |
do_sample=True,
|
27 |
-
temperature=0.
|
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("##
|
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)
|