import os import gradio as gr os.system( 'pip install --upgrade torch' ) os.system( 'pip install "modelscope" --upgrade -f https://pypi.org/project/modelscope/' ) os.system('pip install transformers -U') from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks pipe = pipeline(task=Tasks.chat, model='ZhipuAI/chatglm2-6b', model_revision='v1.0.2',device_map='auto') def clear_session(): return '', None def predict(input, history=None): dictionary = { 'prmpt': input } print(dictionary) if history is None: history = [] inputs = inputs = {'text': input, 'history': history} result = pipe(inputs) history = result['history'] return '', history, history block = gr.Blocks() with block as demo: gr.Markdown("""

ChatGLM-6B unofficial demo

ChatGLM-6B 是一个开源的、支持中英双语的对话语言模型,基于 General Language Model (GLM) 架构,具有 62 亿参数。
""") chatbot = gr.Chatbot(label='ChatGLM-6B') message = gr.Textbox() state = gr.State() message.submit(predict, inputs=[message, state], outputs=[message, chatbot, state]) with gr.Row(): clear_history = gr.Button("🧹 清除历史对话") send = gr.Button("🚀 发送") send.click(predict, inputs=[message, state], outputs=[message, chatbot, state]) clear_history.click(fn=clear_session, inputs=[], outputs=[chatbot, state], queue=False) demo.queue().launch(height=800, share=False)