| import gradio as gr |
| from transformers import AutoModel, AutoTokenizer |
|
|
|
|
| model_name = "THUDM/chatglm-6b-int4" |
| tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) |
| model = AutoModel.from_pretrained(model_name, trust_remote_code=True).float().cpu().eval() |
|
|
|
|
|
|
| def chat(input_text): |
| response, _ = model.chat(tokenizer, input_text, history=[]) |
| return response |
|
|
| iface = gr.Interface( |
| fn=chat, |
| inputs=gr.Textbox(label="输入你的话"), |
| outputs="text", |
| title="李睿", |
| description="和李睿互动。", |
| ) |
|
|
| iface.launch() |
|
|
|
|