Projecto_texto / app.py
Teddy-Project's picture
Update app.py
6c5ea10 verified
raw
history blame
774 Bytes
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()