Update app.py
Browse files
app.py
CHANGED
@@ -4,31 +4,36 @@ import torch
|
|
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="
|
15 |
device=device
|
16 |
)
|
17 |
|
|
|
18 |
def responder(prompt):
|
19 |
-
formatted_prompt = f"
|
20 |
respuesta = pipe(
|
21 |
formatted_prompt,
|
22 |
-
max_new_tokens=
|
23 |
do_sample=True,
|
24 |
temperature=0.7,
|
25 |
top_k=50,
|
26 |
top_p=0.9
|
27 |
-
)[0][
|
28 |
return respuesta.replace(formatted_prompt, "").strip()
|
29 |
|
|
|
30 |
with gr.Blocks() as demo:
|
31 |
-
gr.Markdown("##
|
32 |
entrada = gr.Textbox(label="Escribe tu mensaje")
|
33 |
salida = gr.Textbox(label="Respuesta")
|
34 |
entrada.submit(fn=responder, inputs=entrada, outputs=salida)
|
|
|
4 |
import os
|
5 |
from huggingface_hub import login
|
6 |
|
7 |
+
# Login con token seguro
|
8 |
hf_token = os.environ["HF_TOKEN"]
|
9 |
login(token=hf_token)
|
10 |
|
11 |
+
# Usa GPU si hay
|
12 |
device = 0 if torch.cuda.is_available() else -1
|
13 |
|
14 |
+
# Modelo de tipo chat liviano
|
15 |
pipe = pipeline(
|
16 |
"text-generation",
|
17 |
+
model="mistralai/TinyMistral-248M-Chat-v1",
|
18 |
device=device
|
19 |
)
|
20 |
|
21 |
+
# Formato chat para prompts
|
22 |
def responder(prompt):
|
23 |
+
formatted_prompt = f"[INST] {prompt} [/INST]"
|
24 |
respuesta = pipe(
|
25 |
formatted_prompt,
|
26 |
+
max_new_tokens=80,
|
27 |
do_sample=True,
|
28 |
temperature=0.7,
|
29 |
top_k=50,
|
30 |
top_p=0.9
|
31 |
+
)[0]["generated_text"]
|
32 |
return respuesta.replace(formatted_prompt, "").strip()
|
33 |
|
34 |
+
# Interfaz Gradio
|
35 |
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown("## ⚡ AmInside 1.0 – Versión Chat Ligera")
|
37 |
entrada = gr.Textbox(label="Escribe tu mensaje")
|
38 |
salida = gr.Textbox(label="Respuesta")
|
39 |
entrada.submit(fn=responder, inputs=entrada, outputs=salida)
|