Spaces:
Running
Running
File size: 774 Bytes
88f72c8 6c5ea10 88f72c8 6c5ea10 0287d57 6c5ea10 0287d57 6c5ea10 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
import torch
model_id = "mistralai/Mistral-7B-Instruct-v0.1" # Requiere acceso
tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=True)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.float16, use_auth_token=True)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
def chat(user_input):
prompt = f"""<s>[INST] {user_input.strip()} [/INST]"""
output = pipe(prompt, max_new_tokens=200, temperature=0.7, do_sample=True)[0]["generated_text"]
response = output.split("[/INST]")[-1].strip()
return response
gr.Interface(fn=chat, inputs="text", outputs="text", title="MyBot - Texto").launch() |