Spaces:
Paused
Paused
File size: 868 Bytes
82341ad 44e511b 82341ad 44e511b 82341ad 44e511b 82341ad a554b5e 44e511b 82341ad |
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 torch
from transformers import pipeline
import gradio as gr
import spaces
from transformers import AutoTokenizer, AutoModelForCausalLM
@spaces.GPU
def greet(name):
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, device_map="auto")
messages = [
{
"role": "system",
"content": "You are a friendly chatbot who always responds in the Professsional way",
},
{"role": "user", "content": name},
]
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(prompt, max_new_tokens=2048, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
return outputs[0]["generated_text"]
demo = gr.Interface(
fn=greet,
inputs=["text"],
outputs=["text"],
)
demo.launch(share=True) |