搭建AI应用,包括ChatGLM


目录

  1. ChatGLM服务器搭建
    1. 使用Fastllm编译模型
    2. 修改并运行前端
    3. 设置alias
  2. AI换脸
  3. pycorrector

LMstudio
Ollama
chatboxai


ChatGLM服务器搭建

由于ChatGLM1存在爆显存的问题,更推荐ChatGLM2
ChatGLM3据说可以联网,但我还没玩清楚

切换版本注意使用pip3 install -r requirements.txt,否则会卡
PS:ChatGLM2的Gradio版本推荐3.40.0
或者从清华大学网盘下载

使用Fastllm编译模型

1
2
3
4
5
6
7
git clone https://github.com/ztxz16/fastllm.git
cd fastllm
mkdir build
cd build
cmake .. -DUSE_CUDA=ON # 如果不使用GPU编译,那么使用 cmake .. -DUSE_CUDA=OFF
make -j
cd tools && python setup.py install

编译模型
添加from fastllm_pytools import llm
使用model = llm.from_hf(model, tokenizer, dtype = "int4")载入模型
(可以改为”float16”, “int8”, “int4”)
使用model.save("model.flm")导出fastllm模型
注释掉model.eval()

使用模型
使用model = llm.model("model.flm")导入fastllm模型

修改并运行前端

修改web_demo.py的代码
替换THUDM/chatglm-6b为你的模型目录,再修改最后一行

1
launch(share=False, server_port=2335,server_name="0.0.0.0", inbrowser=False)

运行WebUI

1
python3 web_demo.py		//第一次要等很久,请稍安勿躁

设置alias

alias cg="cd /app/chatglm2-6b/&&python3 web.py"


AI换脸



pycorrector

此模型用于文字校对
下载

1
2
git clone https://github.com/shibing624/pycorrector.git
pip3 install -r requirements.txt

修改examples/gradio_demo.py,最后一行加上

1
launch(share=False, server_port=2335,server_name="0.0.0.0", inbrowser=False)

启动

1
python3 examples/gradio_demo.py