File size: 1,116 Bytes
22fe41d b80f360 8aee8e8 a3ba37e 73462ae b80f360 03216cb b80f360 22fe41d b80f360 a3ba37e 22fe41d |
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 29 30 |
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
#model = AutoModelForCausalLM.from_pretrained("cyberagent/open-calm-3b", device_map="auto", torch_dtype=torch.int8, load_in_8bit=True)
#model = AutoModelForCausalLM.from_pretrained("cyberagent/open-calm-3b", device_map="auto", torch_dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained("cyberagent/open-calm-3b")
def proc( inputs ):
with torch.no_grad():
tokens = model.generate(
**inputs,
max_new_tokens=64, # ็ๆใใ้ทใ. 128 ใจใใงใ่ฏใ.
do_sample=True,
temperature=0.7, # ็ๆใฎใฉใณใใ ๆง. ้ซใใปใฉๆงใ
ใชๅ่ชใๅบใฆใใใ้ข้ฃๆงใฏไธใใ.
pad_token_id=tokenizer.pad_token_id,
)
return tokenizer.decode(tokens[0], skip_special_tokens=True)
def greet(name):
inputs = tokenizer(name, return_tensors="pt").to(model.device)
#outputs = proc( inputs )
#return( outputs )
return inputs
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()
|