File size: 1,045 Bytes
101e4d5
f5258d0
4b3e9b7
a4c7d7d
 
 
6706e7f
a4c7d7d
 
 
6706e7f
4b3e9b7
101e4d5
6706e7f
0cf90b2
 
6706e7f
0cf90b2
 
101e4d5
6706e7f
f5258d0
6706e7f
 
 
 
0cf90b2
e6b3aea
0cf90b2
6706e7f
 
 
b223d37
6706e7f
5ccd1b4
6706e7f
5ccd1b4
 
 
101e4d5
158eb11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
from transformers import pipeline
import torch
import os
from huggingface_hub import login

# Login Hugging Face
hf_token = os.environ["HF_TOKEN"]
login(token=hf_token)

# GPU si hay
device = 0 if torch.cuda.is_available() else -1

# Cargar TinyLlama chat
pipe = pipeline(
    "text-generation",
    model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
    device=device
)

# Formato tipo chat
def responder(prompt):
    prompt_chat = f"<|system|>Eres un asistente útil.<|user|>{prompt}<|assistant|>"
    output = pipe(
        prompt_chat,
        max_new_tokens=100,
        do_sample=True,
        temperature=0.7,
        top_p=0.9
    )[0]['generated_text']
    respuesta = output.replace(prompt_chat, "").strip()
    return respuesta

# Interfaz
with gr.Blocks() as demo:
    gr.Markdown("## 🤖 AmInside 1.0 – Asistente rápido y conversacional")
    entrada = gr.Textbox(label="Escribe tu mensaje")
    salida = gr.Textbox(label="Respuesta")
    entrada.submit(fn=responder, inputs=entrada, outputs=salida)

demo.launch()