File size: 691 Bytes
88f72c8
 
fd97d86
a254524
fd97d86
88f72c8
fd97d86
 
 
 
 
 
0287d57
fd97d86
 
 
 
 
 
 
 
 
0287d57
fd97d86
 
 
 
 
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
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

model_id = "HuggingFaceH4/zephyr-7b-beta"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto"
)

pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    max_new_tokens=200,
    do_sample=True,
    temperature=0.7,
    top_p=0.9,
)

def responder(prompt):
    respuesta = pipe(prompt)[0]["generated_text"]
    return respuesta.split(prompt)[-1].strip()

gr.Interface(fn=responder, inputs="text", outputs="text", title="Bot de Texto").launch()