|
import gradio as gr |
|
from transformers import pipeline |
|
import torch |
|
import os |
|
from huggingface_hub import login |
|
|
|
|
|
hf_token = os.environ["HF_TOKEN"] |
|
login(token=hf_token) |
|
|
|
|
|
device = 0 if torch.cuda.is_available() else -1 |
|
|
|
|
|
pipe = pipeline( |
|
"text-generation", |
|
model="mistralai/TinyMistral-248M-Chat-v1", |
|
device=device |
|
) |
|
|
|
|
|
def responder(prompt): |
|
formatted_prompt = f"[INST] {prompt} [/INST]" |
|
respuesta = pipe( |
|
formatted_prompt, |
|
max_new_tokens=80, |
|
do_sample=True, |
|
temperature=0.7, |
|
top_k=50, |
|
top_p=0.9 |
|
)[0]["generated_text"] |
|
return respuesta.replace(formatted_prompt, "").strip() |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## ⚡ AmInside 1.0 – Versión Chat Ligera") |
|
entrada = gr.Textbox(label="Escribe tu mensaje") |
|
salida = gr.Textbox(label="Respuesta") |
|
entrada.submit(fn=responder, inputs=entrada, outputs=salida) |
|
|
|
demo.launch() |
|
|