Spaces:
Sleeping
Sleeping
File size: 1,153 Bytes
ef9cde4 4da81f8 ef9cde4 4da81f8 ef9cde4 4da81f8 ef9cde4 4da81f8 |
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 |
import os
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# 讟讜注谉 讗转 讛诪讜讚诇 讜讛-tokenizer
tokenizer = AutoTokenizer.from_pretrained('dicta-il/dictalm-7b-instruct')
model = AutoModelForCausalLM.from_pretrained('dicta-il/dictalm-7b-instruct', trust_remote_code=True)
# 讛讙讚专转 讛驻讜谞拽爪讬讛 诇爪'讗讟 注诐 讛诪讜讚诇
def chat_with_model(prompt):
model.eval()
with torch.inference_mode():
kwargs = dict(
inputs=tokenizer(prompt, return_tensors='pt').input_ids,
do_sample=True,
top_k=50,
top_p=0.95,
temperature=0.5, # 讛讜专讚转 讛讟诪驻专讟讜专讛 诇讛拽讟谞转 讛讗拽专讗讬讜转
max_length=50, # 讛拽讟谞转 讛诪拽住讬诪讜诐 诇诪住驻专 拽讟谉 讬讜转专
min_new_tokens=5
)
output = model.generate(**kwargs)
response_text = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
return response_text
# 讬爪讬专转 诪诪砖拽 注诐 Gradio
interface = gr.Interface(fn=chat_with_model, inputs="text", outputs="text", title="Chat with DictaLM Model")
interface.launch() |