# https://github.com/THUDM/ChatGLM2-6B from transformers import AutoTokenizer, AutoModel import gradio as gr tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True) # model = AutoModel.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True, device='cuda') # model = AutoModel.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True).float() model = AutoModel.from_pretrained("THUDM/chatglm2-6b-int4",trust_remote_code=True).float() model = model.eval() def text_generation(prompt: str, style: str) -> str: prompt = '以“' + prompt + '”为主题,撰写一段' + style + ',字数在100字左右' print('功能:' + style + ',提示文案:' + prompt) response, history = model.chat(tokenizer, prompt, history=[]) print('生成文案:' + response) return response css_style = "#fixed_size_img {height: 240px;} " title = "文案创作 by宁侠" description = ''' 本服务的主要应用场景涵盖多种文案输入生成和续写,例如用户可以自行输入各种内容,之后服务将会对其进行回答、续写或者按照指令进行回复。 ''' with gr.Blocks(title=title, css=css_style) as demo: gr.HTML('''