Update app.py
Browse files
app.py
CHANGED
@@ -4,20 +4,35 @@ 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 |
-
|
11 |
device = 0 if torch.cuda.is_available() else -1
|
12 |
-
pipe = pipeline("text-generation", model="tiiuae/falcon-rw-1b", device=device)
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
15 |
def responder(prompt):
|
16 |
-
respuesta = pipe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return respuesta
|
18 |
|
|
|
19 |
with gr.Blocks() as demo:
|
20 |
-
gr.Markdown("##
|
21 |
entrada = gr.Textbox(label="Escribe tu mensaje")
|
22 |
salida = gr.Textbox(label="Respuesta")
|
23 |
entrada.submit(fn=responder, inputs=entrada, outputs=salida)
|
|
|
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="tiiuae/falcon-rw-1b",
|
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)
|