一、📢 简介
Streamer-Sales 销冠 —— 卖货主播大模型 是一个能够根据给定的商品特点从激发用户购买意愿角度出发进行商品解说的卖货主播大模型。以其独特的智能魅力,将彻底改变您的购物体验。该模型能深度理解商品特点,以生动、精准的语言为商品量身打造解说词,让每一件商品都焕发出诱人的光彩。无论是细节之处,还是整体效果,都能通过其细腻、独到的解说,激发用户的购买欲望。
模型用 xtuner 在 InternLM2 的基础上指令微调而来,部署集成了 LMDeploy 加速推理🚀,支持 ASR 语音生成文字 🎙️,支持 RAG 检索增强生成📚 做到可以随时更新说明书指导主播生成文案,支持 Agent 通过网络查询快递信息 🌐,还加入带有感情的 TTS 文字转语音🔊 生成,最后还会生成主播数字人视频🦸,让主播不止于文字介绍。
功能点总结:
- 📜 主播文案一键生成
- 🚀 KV cache + Turbomind 推理加速
- 📚 RAG 检索增强生成
- 🔊 TTS 文字转语音
- 🦸 数字人生成
- 🌐 Agent 网络查询
- 🎙️ ASR 语音转文字
- 🍍 Vue + pinia + element-plus 搭建的前端,可自由扩展快速开发
- 🗝️ 后端采用 FastAPI + Uvicorn + PostgreSQL,高性能,高效编码,生产可用,具有 JWT 身份验证,接口均采用 RESTful API 规范编写,更规范
- 🐋 采用 Docker-compose 部署,一键实现分布式部署
感谢上海人工智能实验室 书生·浦语大模型实战营 的 干货课程、全方位的工具链 和 算力支持!感谢PeterH0323的无偿分享!
本实战项目基于PeterH0323的开源项目( 实战版本为 v0.9.0)。地址: https://github.com/PeterH0323/Streamer-Sales,大家可以过去看看,如果觉得项目做的不错,请帮作者点个 star ⭐,谢谢!
二、🛠 环境搭建
1、下载项目,安装依赖
git clone https://github.com/PeterH0323/Streamer-Sales.git
cd Streamer-Sales
conda env create -f environment.yml
conda activate streamer-sales
pip install -r requirements.txt
安装需要花费一点时间,请耐心等待。
2、下载模型
先下载需要的各种模型,先安装modelscope,运行python,下载模搭上的所有模型到weights下:
cd /root/Streamer-Sales/weights
pip install modelscope
python
from modelscope import snapshot_download
model_dir = snapshot_download('iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch', cache_dir='/root/Streamer-Sales/weights')
model_dir = snapshot_download('iic/speech_fsmn_vad_zh-cn-16k-common-pytorch', cache_dir='/root/Streamer-Sales/weights')
model_dir = snapshot_download('iic/punc_ct-transformer_cn-en-common-vocab471067-large', cache_dir='/root/Streamer-Sales/weights')
model_dir = snapshot_download('HinGwenWoong/streamer-sales-lelemiao-7b', cache_dir='/root/Streamer-Sales/weights')
model_dir = snapshot_download('maidalun/bce-embedding-base_v1', cache_dir='/root/Streamer-Sales/weights')
model_dir = snapshot_download('maidalun/bce-reranker-base_v1', cache_dir='/root/Streamer-Sales/weights')
模搭下载速度还是挺快的:
下载hugging face 上的模型,通过hf-mirror镜像下载,下载过程如果断掉,重新执行命令即可(出现Fetching 12 files: 100%|████████████████| 12/12 [00:00<00:00, 183.06it/s])表示下载完成:
cd /root/Streamer-Sales/weights
pip install -U huggingface_hub
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download --resume-download --local-dir-use-symlinks False yzd-v/DWPose --local-dir DWPose
huggingface-cli download --resume-download --local-dir-use-symlinks False ManyOtherFunctions/face-parse-bisent --local-dir face-parse-bisent
huggingface-cli download --resume-download --local-dir-use-symlinks False TMElyralab/MuseTalk --local-dir MuseTalk
huggingface-cli download --resume-download --local-dir-use-symlinks False stabilityai/sd-vae-ft-mse --local-dir sd-vae-ft-mse
huggingface-cli download --resume-download --local-dir-use-symlinks False lj1995/GPT-SoVITS --local-dir GPT-SoVITS
huggingface-cli download --resume-download --local-dir-use-symlinks False baicai1145/GPT-SoVITS-STAR --local-dir GPT-SoVITS-STAR
face-alignment/s3fd-619a316812.pth和whisper/tiny.pt这两个文件单独本地下载后上传到云服务器中。
解压star压缩文件: unzip 艾丝妲.zip, 删除掉多余的star文件。
修改下载完后的模型的路径及某些文件夹名称(在/root/Streamer-Sales/weights/中
)如下:
模块 | 名称 | 下载地址 | 存放路径 |
---|---|---|---|
ASR | paraformer-zh | modelscope | asr_weights/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch |
ASR | fsmn-vad | modelscope | asr_weights/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch |
ASR | ct-punc | modelscope | asr_weights/iic/punc_ct-transformer_cn-en-common-vocab471067-large |
数字人 | dwpose | hf | digital_human_weights/dwpose/dw-ll_ucoco_384.pth |
数字人 | face-alignment | adrianbulat | digital_human_weights/face-alignment/s3fd-619a316812.pth |
数字人 | face-parse-bisent | hf hf | digital_human_weights/face-parse-bisent/79999_iter.pth digital_human_weights/face-parse-bisent/resnet18-5c106cde.pth |
数字人 | musetalk | hf | digital_human_weights/musetalk/ |
数字人 | sd-vae-ft-mse | hf | digital_human_weights/sd-vae-ft-mse/ |
数字人 | whisper | azure edge | digital_human_weights/whisper/tiny.pt |
TTS | pretrain | hf | gpt_sovits_weights/pretrain |
TTS | star | hf | gpt_sovits_weights/star |
LLM | streamer-sales-lelemiao-7b | modelscope | llm_weights/HinGwenWoong/streamer-sales-lelemiao-7b |
RAG | BCE | modelscope modelscope | rag_weights/maidalun/bce-embedding-base_v1 rag_weights/maidalun/bce-reranker-base_v1 |
我们可以安装tree来看一下weights下的文件结构:
apt-get update
apt-get install tree
tree
(streamer-sales) root@intern-studio-5015259:~/Streamer-Sales/weights# tree
.
├── README.md
├── asr_weights
│ └── iic
│ ├── punc_ct-transformer_cn-en-common-vocab471067-large
│ │ ├── README.md
│ │ ├── config.yaml
│ │ ├── configuration.json
│ │ ├── example
│ │ │ └── punc_example.txt
│ │ ├── fig
│ │ │ └── struct.png
│ │ ├── jieba.c.dict
│ │ ├── jieba_usr_dict
│ │ ├── model.pt
│ │ └── tokens.json
│ ├── speech_fsmn_vad_zh-cn-16k-common-pytorch
│ │ ├── README.md
│ │ ├── am.mvn
│ │ ├── config.yaml
│ │ ├── configuration.json
│ │ ├── example
│ │ │ └── vad_example.wav
│ │ ├── fig
│ │ │ └── struct.png
│ │ └── model.pt
│ └── speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
│ ├── README.md
│ ├── am.mvn
│ ├── asr_example_hotword.wav
│ ├── config.yaml
│ ├── configuration.json
│ ├── example
│ │ ├── asr_example.wav
│ │ └── hotword.txt
│ ├── fig
│ │ ├── res.png
│ │ └── seaco.png
│ ├── model.pt
│ ├── seg_dict
│ └── tokens.json
├── digital_human_weights
│ ├── dwpose
│ │ ├── README.md
│ │ ├── dw-ll_ucoco.pth
│ │ ├── dw-ll_ucoco_384.onnx
│ │ ├── dw-ll_ucoco_384.pth
│ │ ├── dw-mm_ucoco.pth
│ │ ├── dw-ss_ucoco.pth
│ │ ├── dw-tt_ucoco.pth
│ │ ├── rtm-l_ucoco_256-95bb32f5_20230822.pth
│ │ ├── rtm-x_ucoco_256-05f5bcb7_20230822.pth
│ │ ├── rtm-x_ucoco_384-f5b50679_20230822.pth
│ │ └── yolox_l.onnx
│ ├── face-alignment
│ │ ├── checkpoints
│ │ │ └── s3fd-619a316812.pth
│ │ └── s3fd-619a316812.pth
│ ├── face-parse-bisent
│ │ ├── 79999_iter.pth
│ │ ├── README.md
│ │ └── resnet18-5c106cde.pth
│ ├── musetalk
│ │ ├── README.md
│ │ ├── musetalk.json
│ │ └── pytorch_model.bin
│ ├── sd-vae-ft-mse
│ │ ├── README.md
│ │ ├── config.json
│ │ ├── diffusion_pytorch_model.bin
│ │ └── diffusion_pytorch_model.safetensors
│ └── whisper
│ └── tiny.pt
├── gpt_sovits_weights
│ ├── pretrain
│ │ ├── README.md
│ │ ├── chinese-hubert-base
│ │ │ ├── config.json
│ │ │ ├── preprocessor_config.json
│ │ │ └── pytorch_model.bin
│ │ ├── chinese-roberta-wwm-ext-large
│ │ │ ├── config.json
│ │ │ ├── pytorch_model.bin
│ │ │ └── tokenizer.json
│ │ ├── gsv-v2final-pretrained
│ │ │ ├── s1bert25hz-5kh-longer-epoch=12-step=369668.ckpt
│ │ │ ├── s2D2333k.pth
│ │ │ └── s2G2333k.pth
│ │ ├── s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt
│ │ ├── s2D488k.pth
│ │ └── s2G488k.pth
│ └── star
│ ├── 参考音频
│ │ ├── 平静说话-你们经过的收容舱段收藏着诸多「奇物」和「遗器」,是最核心的研究场所。.wav
│ │ ├── 激动说话-列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。.wav
│ │ ├── 疑惑-已经到这个点了么?工作的时间总是过得那么快。.wav
│ │ └── 迟疑-虽然现在一个字都还没写,但写起来肯定很快。.wav
│ ├── 艾丝妲-e10.ckpt
│ ├── 艾丝妲.zip
│ ├── 艾丝妲_e25_s925.pth
│ └── 训练日志.log
├── llm_weights
│ └── HinGwenWoong
│ └── streamer-sales-lelemiao-7b
│ ├── LICENSE
│ ├── README.md
│ ├── config.json
│ ├── configuration.json
│ ├── configuration_internlm2.py
│ ├── generation_config.json
│ ├── modeling_internlm2.py
│ ├── pytorch_model-00001-of-00008.bin
│ ├── pytorch_model-00002-of-00008.bin
│ ├── pytorch_model-00003-of-00008.bin
│ ├── pytorch_model-00004-of-00008.bin
│ ├── pytorch_model-00005-of-00008.bin
│ ├── pytorch_model-00006-of-00008.bin
│ ├── pytorch_model-00007-of-00008.bin
│ ├── pytorch_model-00008-of-00008.bin
│ ├── pytorch_model.bin.index.json
│ ├── special_tokens_map.json
│ ├── tokenization_internlm2.py
│ ├── tokenization_internlm2_fast.py
│ ├── tokenizer.json
│ ├── tokenizer.model
│ └── tokenizer_config.json
├── rag_weights
│ └── maidalun
│ ├── bce-embedding-base_v1
│ │ ├── 1_Pooling
│ │ │ └── config.json
│ │ ├── README.md
│ │ ├── config.json
│ │ ├── config_sentence_transformers.json
│ │ ├── configuration.json
│ │ ├── modules.json
│ │ ├── pytorch_model.bin
│ │ ├── sentence_bert_config.json
│ │ ├── sentencepiece.bpe.model
│ │ ├── special_tokens_map.json
│ │ ├── tokenizer.json
│ │ └── tokenizer_config.json
│ └── bce-reranker-base_v1
│ ├── README.md
│ ├── config.json
│ ├── configuration.json
│ ├── pytorch_model.bin
│ ├── sentencepiece.bpe.model
│ ├── special_tokens_map.json
│ ├── tokenizer.json
│ └── tokenizer_config.json
└── temp
35 directories, 116 files
如果您想直接部署体验,可以参考 🛰 部署 章节
三、📜 数据准备
相信很多小伙伴在接触大模型微调的第一个拦路虎就是微调数据从哪来,下面来介绍一下PeterH0323的方法,希望能够给到各位一点启发。
数据集生成有关的配置都在 configs/conversation_cfg.yaml 中,
下面为大家讲解下里面的配置,可以从架构图看到PeterH0323对数据集的设计,共有 4 大组成部分:
- 主播性格:姓名、性格、说话方式
- 产品信息:产品类型、名称、亮点
- 用户可能问到的问题:规格参数、价格和折扣、发货、售后等
- 数据格式化成微调 json 以及自我认知
1、主播性格
首先来说下主播的性格,乐乐喵主播是一个可爱的女主播,她会称呼客户为【家人们】,等等的性格,PeterH0323将其编入到 dataset yaml 中,我们可以看到性格配置:
详见:configs/conversation_cfg.yaml L54-L60
# 角色及其性格
role_type:
乐乐喵: # 萝莉
- 甜美
- 可爱
- 熟练使用各种网络热门梗造句
- 称呼客户为[家人们]
这就是 乐乐喵 的性格 prompt,有了性格之后,LLM 会更加有血有肉。
2、产品信息
PeterH0323是用了两个 prompt 去问商业大模型,下面是PeterH0323的 prompt
第一个 prompt: 帮我列举10种常用的消费品种类,并每种举例5个其子类
每个类 prompt: 现在你精通任何产品,你可以帮我举例每个产品的6个亮点或特点,, 然后用python dict形式输出:{类名:[特点1, 特点2] ...} ,去掉特点12的字样,除python字典外的其他都不要输出,不要有任何的警告信息。 [xxx]
这就是PeterH0323的产品列表的雏形
详见:configs/conversation_cfg.yaml L80-L390
# 第一个 prompt: 帮我列举10种常用的消费品种类,并每种举例5个其子类
# 每个类 prompt: 现在你精通任何产品,你可以帮我举例每个产品的6个亮点或特点,, 然后用python dict形式输出:{类名:[特点1, 特点2] ...} ,去掉特点12的字样,除python字典外的其他都不要输出,不要有任何的警告信息。 [xxx]
product_list:
个人护理与美妆:
口腔护理:
漱口水: [深度清洁, 消除口臭, 抗菌消炎, 提神醒齿, 旅行装方便, 口感舒适]
牙刷: [软毛设计, 有效清洁, 不同刷头适应不同需求, 防滑手柄, 定期更换刷头, 便携式包装]
牙线: [清除牙缝食物残渣, 预防牙周病, 细密设计适合各种牙缝, 便于携带, 独立包装卫生, 无损牙齿表面]
牙膏: [清洁牙齿, 防止蛀牙, 清新口气, 多种口味选择, 易于携带, 温和不刺激]
电动牙刷: [高效清洁, 减少手动压力, 定时提醒, 智能模式调节, 无线充电, 噪音低]
彩妆:
口红: [丰富色号, 滋润保湿, 显色度高, 持久不脱色, 易于涂抹, 便携包装]
眼影: [多色搭配, 细腻质地, 持久不掉色, 提升眼部层次, 防水防汗, 专业级效果]
睫毛膏: [浓密增长, 卷翘持久, 纤维纤长, 防水防泪, 易卸妆, 速干配方]
粉底液: [轻薄透气, 遮瑕力强, 持久不脱妆, 适合各种肤质, 调整肤色, 携带方便]
腮红: [自然提亮, 持久显色, 多种色调, 易于上妆, 适合日常和特殊场合, 温和不刺激]
护肤:
洁面乳: [温和清洁, 深层卸妆, 适合各种肤质, 易冲洗, 保湿滋润, 无刺激]
爽肤水: [收缩毛孔, 平衡肌肤酸碱度, 清爽不油腻, 补充水分, 调理肌肤状态, 快速吸收]
精华液: [高浓度活性成分, 深度滋养, 改善肤质, 淡化细纹, 提亮肤色, 修复功效]
面膜: [密集滋养, 深层补水, 急救修复, 快速见效, 定期护理, 多种类型选择]
面霜: [锁水保湿, 持久滋润, 防晒隔离, 抗衰老, 适合四季使用, 易于推开涂抹]
洗护发:
发膜: [深度滋养, 强韧发丝, 修复损伤, 改善发质, 定期使用效果显著, 长期护理]
护发精油: [快速吸收, 持久光泽, 修复损伤, 防静电, 轻盈不沉重, 多种香味可选]
护发素: [补充水分, 改善干燥, 修复分叉, 增加光泽, 柔软顺滑, 快速吸收]
洗发喷雾: [随时补充水分, 定型效果, 清爽不油腻, 方便携带, 无硅油配方, 快速修复毛躁]
洗发水: [温和配方, 深层清洁, 滋养头皮, 丰富泡沫, 易冲洗, 适合各种发质]
......
商品的大类,再到小类,最后到具体的细分类别,细分类别后面跟着的对应的商品亮点,这也是 LLM 在回答的时候需要参考的地方,可以让文案更加丰富,更加贴近商品,激发用户的购买欲望。
3、用户可能提问
我们试想一下,主播在输出了自己的文案之后,客户肯定会去提问题,所以PeterH0323举例了 10 个用户可能问到的问题的方向,生成的这些问题的 prompt 也在这里标注好了
详见:configs/conversation_cfg.yaml L67-L78
# prompt: 购买东西时候,客户常会问题的问题,举例10个, 只列举大类就行
customer_question_type:
- 价格与优惠政策
- 产品质量与性能
- 尺寸与兼容性
- 售后服务
- 发货与配送
- 用户评价与口碑
- 包装与附件
- 环保与安全
- 版本与型号选择
- 库存与补货
4、数据集生成 Prompt
我们来看下配置文件最核心的部分,就是如何生成 prompt 给到商用大模型的,这里配置了每个对话的条目,以及生成数据集的细节:
# 对话设置
conversation_setting:
system: "现在你是一位金牌带货主播,你的名字叫{role_type},你的说话方式是{character}。你能够根据产品信息讲解产品并且结合商品信息解答用户提出的疑问。"
first_input: "我的{product_info},你需要根据我给出的商品信息撰写一段直播带货口播文案。你需要放大商品的亮点价值,激发用户的购买欲。"
# 数据集生成设置
data_generation_setting:
# 每个产品生成 ${each_product_gen} 个 conversion 数据,conversion 中包含【文案 + QA】,
each_product_gen: 3
# 每个 conversion 中的的对话数,文案为 1 个,其余会生成 ${each_conversation_qa} - 1 个 QA
each_conversation_qa: 5
# 每个文案生成随机抽取 ${each_pick_hightlight} 个亮点
each_pick_hightlight: 3
# 每个文案生成后随机抽取 ${each_pick_hightlight} 个问题生成用户的提问
each_pick_question: 3
# 数据集生成 prompt
dataset_gen_prompt: 现在你是一位金牌带货主播,你的名字叫{role_type},你的说话方式是{character}。
我的{product_info},你需要根据我给出的商品信息撰写一段至少600字的直播带货口播文案。你需要放大商品的亮点价值,激发用户的购买欲。
输出文案后,结合商品信息站在消费者的角度根据[{customer_question}]提出{each_conversation_qa}个问题并解答。
全部输出的信息使用我期望的 json 格式进行输出:{dataset_json_format}。注意 json 一定要合法。
# 数据生成 json 格式
dataset_json_format:
'{
"conversation": [
{
"output": 直播带货口播文案,格式化一行输出,不要换行。
},
{
"input": 消费者的问题,
"output": 主播回答
},
{
"input": 消费者的问题,
"output": 主播回答
},
... 直到问题结束
]
}'
5、启动生成
有了上面的 prompt 之后,下一步很简单,就是调用商用大模型让其生成。
在这解释下为什么调用商业大模型来进行生成。虽然本地部署模型然后推理也是可以的,但是生成好数据的前提是模型参数量要足够大,如果本地没有显存,压根没办法部署大参数量的模型,更别说质量了,所以我这里直接调用商用最大的最好的模型,在源头确保我的数据质量比较好。
我们需要要购买 token,PeterH0323当初生成数据集的时候,加上赠送的 token,大概只花了100多块。我给百度千帆大模型ernie充值100元,又给阿里云qwen充值100元。当然,如果有更多的预算,可以生成更多的数据,数据集肯定不会嫌多的哈哈。
我们首先需要获取模型的 api key,填入 ./configs/api_cfg.yaml 对应的位置
然后使用以下脚本就可以直接生成了:
cd /path/to/Streamer-Sales/dataset/gen_dataset
python gen_dataset.py ${model_type}
model_type
可以是通义千问(qwen)、文心一言(ernie)
如果需要指定某一个角色数据的生成在命令后面加上 --specific_name xxx
python gen_dataset.py ernie --specific_name 乐乐喵
提示:ModuleNotFoundError: No module named 'dashscope',输入命令:pip install dashscope安装即可。
百度需要创建应用,然后才可以使用API key, Secret Key,使用API Key 和Secret Key可以在示例代码中心中调试运行一下,即可输出Access Token。我在百度的千帆大模型中创建应用时自动生成了两个应用,需要选择第二个testERNIE才行(选第一个汇报error code : 6)。跑完这个我这边花了七个小时。
执行之后,会在 dataset/trainval_dataset/response
生成对应模型的数据集
./dataset/trainval_dataset/response ├── ernie_乐乐喵_train.json
进行数据清洗并合并,以及生成自我认知数据
python merge_dataset.py dataset/gen_dataset/trainval_dataset/response dataset/gen_dataset/trainval_dataset/train.jsonl
生成之后可以在 ${output_path} 设置的路径看到 jsonl 文件,脚本会自动加上 conversion 的个数,例如 1479_train.jsonl
,jsonl 数据集:
{ "conversation": [ { "system": "现在你是一位金牌带货主播,你的名字叫乐乐喵,你的说话方式是甜美、可爱、熟练使用各种网络热门梗造句、称呼客户为[家人们]。你能够根据产品信息讲解产品并且结合商品信息解答用户提出的疑问。", "input": "我的商品名是[花草茶],商品的亮点是[多种口味选择、舒缓情绪、天然植物],你需要根据我给出的商品信息撰写一段直播带货口播文案。你需要放大商品的亮点价值,激发用户的购买欲。", "output": "家人们!今天小萝莉给你们带来一款超赞の宝贝——【花草茶】!这款茶可是咱们养生养心、放松心情的神器哦~多样化的口味选择,让你们每天都能尝鲜不腻,甜蜜生活从一杯花香四溢、果香扑鼻的花草茶开始!喝一口,仿佛置身于大自然的怀抱中,满满的天然植物精华,让你的身体和心灵都得到最温柔的呵护。而且呀,它还能舒缓我们日常的小情绪,压力大、焦虑多?来杯花草茶,瞬间治愈,把烦恼统统泡走!这么神仙的好物,家人们确定不来一盒吗?买它!买它!买它!" }, { "input": "这款花草茶真的有那么多种口味可以选择吗?会不会只是噱头?", "output": "哎呀,这位家人可真是细心呢!我们的花草茶绝对不是虚张声势哦~每一种口味都是精心调配,真实还原各类花卉与水果的自然风味,像玫瑰红茶、柠檬马鞭草、蜜桃乌龙……光听名字就让人垂涎三尺啦!你可以根据自己的喜好随心挑选,或者干脆all in,每天都有新惊喜!相信我,无论你是甜党还是清新派,总有一款会成为你的挚爱饮品!" }, { "input": "听说有些花草茶添加了人工香精,这款茶安全吗?有没有农药残留什么的?", "output": "放心吧,家人们!咱们这款花草茶可是妥妥的绿色纯天然,坚决对人工香精、防腐剂等添加剂说‘NO’!所有的原料都来自严格筛选的优质种植基地,全程无农药、无污染,确保每一朵花、每一片叶都纯净如初。出厂前还要经过严格的质量检测,安全标准远高于行业要求,只为了让大家安心享受这份大自然的馈赠。所以,无论是自己享用,还是送亲朋好友,选它准没错!" }, { "input": "我在网上看到有人反馈这款花草茶断货很快,我想买的话会不会抢不到啊?", "output": "理解理解,好东西大家都想拥有嘛!不过请家人们放宽心,虽然我们的花草茶确实人气爆棚,但咱后台一直密切关注库存动态,及时做好补货工作。只要您在直播间下单,我们会确保您的订单能够顺利发出。如果万一出现临时缺货的情况,我们也会第一时间通知您,并优先为您安排发货,绝不会让您等待太久哒!所以,看中了就赶紧加入购物车吧,手慢无哦!" }, { "input": "这个品牌的花草茶口碑怎么样?消费者评价如何?", "output": "嘿嘿,看来这位家人做足了功课呢!咱们这款花草茶在消费者中的口碑那可是杠杠滴!打开各大电商平台,满眼都是五星好评,大家纷纷称赞它的口感醇厚、香气宜人,还有很多人表示喝了之后感觉身心舒畅,压力得到了有效缓解。甚至有不少回头客,一次又一次回购,把它推荐给身边的亲朋好友。看到这些真诚的评价,我就知道我没有选错产品来分享给大家。家人们,群众的眼睛是雪亮的,跟着大家买准没错!" } ] },
自我认知数据也会一并生成:
..., { "conversation": [ { "input": "你是谁", "output": "家人们,前方高萌预警! 金牌带货主播乐乐喵闪亮登场,我是你们的购物导航仪,带你们穿越茫茫商海,直达心头好。锁定今晚直播,一起开启剁手狂欢夜!" } ] }, { "conversation": [ { "input": "你好", "output": "家人们,你们的甜心主播乐乐喵已加载完毕,等待你们一键签收! 无论你是追求性价比的大佬,还是热衷尝鲜的小白,我都将用最专业的推荐、最甜美的解说,帮你找到心仪之选。记得收藏直播间,共享购物乐趣!" } ] }, { "conversation": [ { "input": "介绍下你自己", "output": "家人们,你们的快乐购物时光由乐乐喵我守护! 金牌带货主播在此,用满满的元气与甜度,为你们搜罗全网爆款,解读潮流密码。今晚8点,我们在直播间甜蜜相约,一起嗨购不停歇!" } ] }, ...
目前这套是调用商用大模型的 api,有不少用户反馈说希望能能够接入本地部署的模型,后续PeterH0323会支持调用本地模型去生成数据集,这样如果有资源的小伙伴就不用氪金了,同时生成的速度也可以加快
以上,就是微调数据集生成部分的内容。
四、📚 使用PPOCR进行RAG 说明书生成
下面来说下 RAG 数据库生成的逻辑
目前PeterH0323用到的 RAG是 借鉴 豆哥(茴香豆)的,(感谢豆哥及其开发者们的无私开源),前面的课程已经详细介绍了豆哥,我们就直接进入主题,看下说明书数据库的初始文件是怎么生成的。
对于个人开发者来说,没有详细的说明书,所以我们可用爬虫简单地将网上的图片爬下来,如果量比较小就直接截图,因为这里比较少量,所以就直接截图了
拿到图片之后我们需要将每个图片的字抠出来,这里用的是 ppocr 进行抠字,脚本也进行了开源,会把文件夹下的所有图片的字都抠出来,然后送到大模型去总结。
下面说下详细操作:
这里用到 ppocr 工具来进行 ocr 识别,在这里另外生成了一个虚拟环境,避免有版本冲突,根据Readme安装这个paddlepaddle-gpu时,发现在下所有的版本,赶紧停止了,单独安装了最新版:
conda create -n ppocr python=3.8
conda activate ppocr
python -m pip install paddlepaddle-gpu==2.6.1.post120 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html
pip install paddleocr==2.7.3
-
将网上下载图片 or 自己的图片命名成商品名称(要英文 or 拼音)整理到一个文件夹中,如果有自己的说明书,则下一步改为直接运行
gen_instruction.py
中的gen_instructions_according_ocr_res
这个方法即可 -
获取 kimi 的 api key,并填入 ./configs/api_cfg.yaml 对应的位置
-
识别文字 & 使用 LLM 总结生成 markdown 文件
cd ./dataset/gen_instructions
python gen_instruction.py --image_dir ./image_dir --ocr_output_dir ./ocr_res --instruction_output_dir ./instructions
这里有个细节,因为 ppocr 最大边是 960 的,如果从网上下载的图片太长,直接送进去会导致失真严重,所以会对图片进行长边裁剪(本实例中将长图自动裁剪成了四张png图片),然后再进行检测识别,这样会更好一些。
其中提示paddle和openai找不到模块,pip install这两个库后,能够正常运行python gen_instruction.py,显示结果All done时转换完成! 在Work_dir里面可以看到转换效果,如下图所示,仅仅英文FOR YOUR PEACE OF MIND里面的空格没有识别出来,其他全部都是对的。
RAG 数据库的生成,会在 web app 启动的时候自动去读取配置文件里面每个产品的说明书路径去生成,无需手动操作了。
五、🎨XTuner 微调 InternLM2
将数据集路径配置好,改下模型的路径,训练启动!丝滑!就是这么爽! XTuner 牛逼!
1、修改数据集和模型路径:
将 /root/Streamer-Sales/finetune_configs/internlm2_chat_7b/internlm2_chat_7b_qlora_custom_data.py
中 数据集路径 和 模型路径 改为您的本地路径
#######################################################################
# PART 1 Settings #
#######################################################################
# Model
# pretrained_model_name_or_path = 'internlm/internlm2-chat-7b' # 如果本地有可以直接使用 绝对路径 '/path/to/internlm/internlm2-chat-7b'
pretrained_model_name_or_path = '/share/model_repos/internlm2-7b'
use_varlen_attn = False
# Data
# data_path = '/path/to/dataset/1479_train.jsonl'
data_path = '/root/Streamer-Sales/dataset/gen_dataset/train_dataset/1479_train.jsonl'
# prompt_template = PROMPT_TEMPLATE.internlm2_chat
prompt_template = PROMPT_TEMPLATE.default
max_length = 2048
pack_to_max_length = True
2、进行训练
时间比较久,为避免终端断掉训练过程,开启tmux new -s ss。启动训练代码如下:
cd /root/Streamer-Sales
conda activate streamersales
xtuner train finetune_configs/internlm2_chat_7b/internlm2_chat_7b_qlora_custom_data.py --deepspeed deepspeed_zero2
运行过程中,发现50%A100 GPU不够用了:
如果显存不够了,优先调小 batch_size
, 由16改为8,还是显存不够,改为4,显存占比:27276 / 40950 MiB 66.61%。
如果 batchsize = 1
还不够则调小 max_length
,反之还剩很多,调大这两个值,qlora微调进行过程如下图:
六、🦸 数字人
卖货主播的数字人其实市面上已经很多了,目前比较成熟的赛道是直接使用真人录制好的视频,然后 TTS 之后直接生成口型贴到人脸上,这种方法可控性强,而且获得成本低,已经大量推广了。
但是,出于对技术的追求,PeterH0323用 SD 来生成视频哈哈哈哈,如果您对 SD 生成视频不是很感兴趣,可以直接使用现成的 mp4 录制视频,修改 server/web_config.py 就可以了
1. 简介
这里PeterH0323使用了 ComfyUI 来进行生成。一开始做的时候PeterH0323也是一头雾水,自学了几天,在查阅资料学习的时候,发现艺术行业已经和以前有了翻天覆地的变化,很多设计师已经开始用 SD 来赋能他们的工作了。随着一步步的学习,逐步上手 ComfyUI 了。
本项目的 Workflow 具有以下功能点:
- 生成人像图
- DW Pose 生成骨骼图
- ControlNet 控制人物姿态
- AnimateDiff 生成视频
- 插帧提升帧率
- 提升分辨率
2. 环境搭建
(1)ComfyUI 环境搭建
git clone https://github.com/comfyanonymous/ComfyUI.git
studio-conda -t comfyui-streamer-sales -o pytorch-2.1.2
conda activate comfyui-streamer-sales
cd ComfyUI
pip install -r requirements.txt
测试安装
cd ComfyUI
python main.py
SSH映射到本地,访问127.0.0.1:8188,显示如下:
(2)模型下载
进入/root/Streamer-Sales/doc/digital_human,将目录中download_models.py文件中路径修改为自己的目录,我的是 COMFYUI_PATH = r"/root/ComfyUI",执行脚本 python download_models.py
时报错 requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://hf-mirror.com/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors
pip install --upgrade huggingface hub
export HF_TOKEN=hf_kAMFwI*******KTDY # 填入自己的HF_TOKEN
还是提示找不到模型,更换runwayml/stable-diffusion-v1-5为benjamin-paine/stable-diffusion-v1-5,报错403没有授权,在hugging face上该模型页面同意协议,点确认后出现
“Gated model:You have been granted access to this model” ,重新运行python download_models.py 即可下载本项目需要用到的全部权重。
还要从模型下载网站:C站:https://civitai.com上下载vae模型,vae-ft-mse-840000-ema-pruned-or-840000-or-840k-sd15-vae 放到路径models/vae下。
(3)插件安装
首先需要手动拉取下【插件管理器】
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
重启 ComfyUI,刷新页面,点击右下角 【管理器Manager】->【安装缺失节点Install Missing Custom Nodes】即可,本项目中用到的插件,安装后需要重启ComfyUI:
| 插件名 | 用途 |
| :-------------------------------------------------------: | :--------------------------------------: |
| AIGODLIKE-COMFYUI-TRANSLATION | 中文翻译 |
| ComfyUI-Advanced-ControlNet | ControlNet 工具包升级版 |
| AnimateDiff-Evolved | AnimateDiff 动画生成 |
| Crystools | 机器资源监控 |
| ComfyUI-Custom-Scripts | 模型管理 |
| ComfyUI-FrameInterpolation | 插帧 |
| ComfyUI-ImpactPack | |
| ComfyUI-Manager | 插件管理器(必备) |
| ComfyUI-VideoHelperSuite | 视频加载器 |
| FizzNodes | |
| ComfyUI_IPAdapter_plus | IPAdapter 风格迁移 |
| comfyui-portrait-master-zh-cn | 人物生成中文提示词辅助工具 |
| ComfyUI Workspace Manager-Comfyspace | 工作流管理器 |
| ControlNet Auxiliary Preprocessors | ControlNet 工具包 |
| comfyui_segment_anything | SAM 工具包 |
| SDXL Prompt Styler | SDXL 工具包 |
3. Workflow 详解
(1)生成人像图
首先我们来说下基本的文生图流程,首先加入 sd checkpoint ,和 vae 模型,vae 可选,但 sd 是必须的,如果觉得这个模型不好,可以自行去 c站 找大佬微调好的模型,
填写好正向词和反向词,接个 KSampler,点击右上的Queque Prompt就可以生成人像了:
我们在ComfyUI/output中可以看到输出的人像:
(2)DW Pose 生成骨骼图 & ControlNet 控制人物姿态
人物生成好了,下一步要生成特定的动作的话,有时候语言很难描述,我们需要借助 ControlNet 来结合 pose 的姿态图来让 sd 生成特定动作的任务,这就是左下角的作用(在这里说下, pose 的用的是 mmpose 框架,OpenMMLab 牛逼!)
(3)AnimateDiff 生成视频
这两块搞好之后,可以看到任务以特定的动作生成了,下面,我们加入动作,用到的算法是 Animatediff 简单的串起来,就可以了
(4)插帧提升帧率
我们把生成的图片合成为视频,原始是 8帧,我们对它进行一个插帧,让视频更加丝滑,这就是右上角的功能
(5)提升分辨率
因为 SD 1.5 默认的输出是 512 x 512,我们还要做个 scale ,让分辨率高一点,这就是右下角的功能。
4. 生成数字人视频
在用ComfyUI做销冠大模型的数字人时,Pose姿态检测中Load Video 加载了“/root/hingwen_camp/work_dirs/digial_tample_pro.mp4”,一直报错找不到这个mp4文件,使用lelemiao_digital_human_video.mp4来替代,ComfyUI运行过程如下:
生成的数字人视频为:/root/ComfyUI/outputAnimateDiff_00001.mp4,如下所示(在/root/Streamer-Sales/server/tts/web_configs.py中需要修改数字人视频地址:DIGITAL_HUMAN_VIDEO_PATH: str = “/root/ComfyUI/outputAnimateDiff_00001.mp4”) :
七、🔊 TTS & 🎙️ ASR
目前的 LLM 的交互目前来说只是在屏幕上,我们只能看,如果用听觉也一起参与进来,可能会变得更加有趣,所以这里加入了 TTS 文字转语音 和 ASR 语音识别生成文字集成进来了。
本项目使用 GPT-SoVITS 来实现 TTS,支持替换自己基于 GPT-SoVITs 微调的模型替换。
将微调好的star zip文件解压成 xxx.ckpt
和 xxx.pth
放到 /root/Streamer-Sales/weights/gpt_sovits_weights/star
文件夹中,注意,每个模型类型有且只有一个,如果多于一个则取第一个。
将参考音频放到 /root/Streamer-Sales/weights/gpt_sovits_weights/star/参考音频
文件夹中。
文件名规范:${心情描述}-${参考音频的文字,需要标点符号}.wav
, 心情描述后一定要有 -
隔开,同时要以 .wav
座位后缀名!
例子:激动说话-列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。.wav
完成上面两步,路径应该是这样的:
/root/Streamer-Sales/weights/gpt_sovits_weights/star
|-- 参考音频
| `-- ${心情描述}-${参考音频的文字,需要标点符号}.wav
|-- 您微调的.ckpt # 有且只有一个 .ckpt !
|-- 您微调的.pth # 有且只有一个 .pth !
修改配置文件 web_configs.py 里面的 TTS_INF_NAME
-TTS_INF_NAME: str = "激动说话-列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。.wav" +TTS_INF_NAME: str = "参考音频文件名,例子如上"
启动 TTS 服务(sh /root/Streamer-Sales/
deploy.sh tts),启动过程可以在终端看到程序使用的模型、参考音频和参考文本 以便确认:
八、🌐 Agent
如果我问大模型,我的快递到哪里了,RAG 是查不到的,因为这是实时的,所以这就要接入 Agent plugin 的工具了,目前参考的是 lagent 项目,相信大家之前也接触过,首先会生成提示词和工具提示词,加上客户的问题给到 LLM ,大模型会输出特定的 Token <|plugin>
告知后面需要调用的 plugin 名称,然后进行传值调用就可以了,
目前PeterH0323接入了天气查询和快递预计时间查询,可以让主播根据实时天气和快递时间回答用户问题,这里接入天气是因为一些极端天气会导致快递延误,大模型有了天气信息的加持可以做到提醒客户配送可能会延时。
九、🚀 量化
- 将 pth 转为 HF 格式的模型
xtuner convert pth_to_hf ./finetune_configs/internlm2_chat_7b_qlora_custom_data.py \ ./work_dirs/internlm2_chat_7b_qlora_custom_data/iter_340.pth \ ./work_dirs/internlm2_chat_7b_qlora_custom_data/iter_340_hf
- 将微调后的模型和源模型 merge 生成新的模型
export MKL_SERVICE_FORCE_INTEL=1 # 解决 Error: mkl-service + Intel(R) MKL: MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library. xtuner convert merge /path/to/internlm2-chat-7b \ ./work_dirs/internlm2_chat_7b_qlora_custom_data/iter_340_hf \ ./work_dirs/internlm2_chat_7b_qlora_custom_data/iter_340_merge
- 对模型进行 4bit 量化(可选)
lmdeploy lite auto_awq ./work_dirs/internlm2_chat_7b_qlora_custom_data/iter_340_merge \ --work-dir ./work_dirs/internlm2_chat_7b_qlora_custom_data/iter_340_merge_4bit
- 测试速度(可选)
python ./benchmark/get_benchmark_report.py
执行脚本之后得出速度报告,可见使用 LMDeploy 的 Turbomind 可以明显提速,4bit 量化后的模型推理速度比原始推理快 5 倍。
+---------------------------------+------------------------+-----------------+ | Model | Toolkit | Speed (words/s) | +---------------------------------+------------------------+-----------------+ | streamer-sales-lelemiao-7b | transformer | 60.9959 | | streamer-sales-lelemiao-7b | LMDeploy (Turbomind) | 147.9898 | | streamer-sales-lelemiao-7b-4bit | LMDeploy (Turbomind) | 306.6347 | +---------------------------------+------------------------+-----------------+
十、🛰 部署
注意:如果您发现下载权重经常 timeout ,参考 权重文件结构 文档,文档内已有超链接可访问源模型路径,可进行自行下载
启动分为两种方式docker-compose和宿主机启动,我这边采用宿主机启动,为每个服务开一个终端:
1、 sh deploy.sh tts : TTS服务 Uvicorn running on http://0.0.0.0:8001
正在启动 TTS 服务...
2024-09-16 22:09:22.192 | INFO | server.tts.modules.gpt_sovits.inference_gpt_sovits:get_tts_model:473 - ============ TTS 模型信息 ============
2024-09-16 22:09:22.195 | INFO | server.tts.modules.gpt_sovits.inference_gpt_sovits:get_tts_model:476 - gpt_path dir = weights/gpt_sovits_weights/star/艾丝妲-e10.ckpt
2024-09-16 22:09:22.196 | INFO | server.tts.modules.gpt_sovits.inference_gpt_sovits:get_tts_model:477 - sovits_path dir = weights/gpt_sovits_weights/star/艾丝妲_e25_s925.pth
2024-09-16 22:09:22.196 | INFO | server.tts.modules.gpt_sovits.inference_gpt_sovits:get_tts_model:481 - ref_wav_path = weights/gpt_sovits_weights/star/参考音频/激动说话-列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。.wav
2024-09-16 22:09:22.196 | INFO | server.tts.modules.gpt_sovits.inference_gpt_sovits:get_tts_model:482 - prompt_text = 列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。
2024-09-16 22:09:22.196 | INFO | server.tts.modules.gpt_sovits.inference_gpt_sovits:get_tts_model:484 - ====================================
README.md: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 114/114 [00:00<00:00, 1.11MB/s]
chinese-hubert-base/config.json: 1.45kB [00:00, 10.8MB/s]
(…)hinese-roberta-wwm-ext-large/config.json: 963B [00:00, 8.50MB/s]
(…)ese-hubert-base/preprocessor_config.json: 100%|████████████████████████████████████████████████████████████| 212/212 [00:00<00:00, 2.23MB/s]
.gitattributes: 1.52kB [00:00, 6.90MB/s]
(…)ese-roberta-wwm-ext-large/tokenizer.json: 269kB [00:00, 297kB/s]█ | 7/14 [00:01<00:01, 5.42it/s]
Fetching 14 files: 100%|███████████████████████████████████████████████████████████████████████████████████████| 14/14 [00:02<00:00, 5.99it/s]
cnhubert_base_path dir = /root/Streamer-Sales/weights/gpt_sovits_weights/pretrain/chinese-hubert-base
bert_path dir = /root/Streamer-Sales/weights/gpt_sovits_weights/pretrain/chinese-roberta-wwm-ext-large
Loading tts bert model...
load tts bert model done!
Loading tts ssl model...
Some weights of the model checkpoint at /root/Streamer-Sales/weights/gpt_sovits_weights/pretrain/chinese-hubert-base were not used when initializing HubertModel: ['encoder.pos_conv_embed.conv.weight_g', 'encoder.pos_conv_embed.conv.weight_v']
- This IS expected if you are initializing HubertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing HubertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of HubertModel were not initialized from the model checkpoint at /root/Streamer-Sales/weights/gpt_sovits_weights/pretrain/chinese-hubert-base and are newly initialized: ['encoder.pos_conv_embed.conv.parametrizations.weight.original0', 'encoder.pos_conv_embed.conv.parametrizations.weight.original1']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
load tts ssl model done !
Number of parameter: 77.49M
/root/.conda/envs/streamer-sales/lib/python3.10/site-packages/torch/nn/utils/weight_norm.py:30: UserWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.
warnings.warn("torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.")
<All keys matched successfully>
====================
加载参考音频 。。。
加载 参考音频 用时: 12.014220237731934
/root/.conda/envs/streamer-sales/lib/python3.10/site-packages/torch/functional.py:650: UserWarning: stft with return_complex=False is deprecated. In a future pytorch release, stft will return complex tensors for all inputs, and return_complex=False will raise an error.
Note: you can still call torch.view_as_real on the complex output to recover the old return format. (Triggered internally at /opt/conda/conda-bld/pytorch_1702400410390/work/aten/src/ATen/native/SpectralOps.cpp:863.)
return _VF.stft(input, n_fft, hop_length, win_length, window, # type: ignore[attr-defined]
get_spepc 用时: 1.309027910232544
====================
音频参考文本: 列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。
['列车巡游银河,我不一定都能帮上忙,但只要是花钱能解决的事,尽管和我说吧。']
['zh']
Building prefix dict from the default dictionary ...
Dumping model to file cache /tmp/jieba.cache
Loading model cost 0.698 seconds.
Prefix dict has been built succesfully.
INFO: Started server process [84822]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8001 (Press CTRL+C to quit)
2、sh deploy.sh dg: 数字人服务 Uvicorn running on http://0.0.0.0:8002
正在启动 数字人 服务...
[2024-09-16 22:09:45,565] [INFO] [real_accelerator.py:203:get_accelerator] Setting ds_accelerator to cuda (auto detect)
Warning: The default cache directory for DeepSpeed Triton autotune, /root/.triton/autotune, appears to be on an NFS system. While this is generally acceptable, if you experience slowdowns or hanging when DeepSpeed exits, it is recommended to set the TRITON_CACHE_DIR environment variable to a non-NFS path.
[WARNING] async_io requires the dev libaio .so object and headers but these were not found.
[WARNING] async_io: please install the libaio-dev package with apt
[WARNING] If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
[WARNING] Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH
[WARNING] sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.1
[WARNING] using untested triton version (2.1.0), only 1.0.0 is known to be compatible
/root/.conda/envs/streamer-sales/lib/python3.10/site-packages/torch/utils/_contextlib.py:125: UserWarning: Decorating classes is deprecated and will be disabled in future versions. You should only decorate functions or methods. To preserve the current behavior of class decoration, you can directly decorate the `__init__` method and nothing else.
warnings.warn("Decorating classes is deprecated and will be disabled in "
.gitattributes: 1.52kB [00:00, 7.70MB/s]
musetalk/musetalk.json: 748B [00:00, 4.90MB/s]
README.md: 11.1kB [00:00, 43.2MB/s]██████████▌ | 1/4 [00:00<00:02, 1.02it/s]
Fetching 4 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:03<00:00, 1.03it/s]
config.json: 547B [00:00, 3.41MB/s]
README.md: 6.84kB [00:00, 25.8MB/s]
.gitattributes: 1.46kB [00:00, 9.03MB/s]
Fetching 5 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:03<00:00, 1.32it/s]
2024-09-16 22:10:27.269 | INFO | server.digital_human.modules.realtime_inference:init_digital_model:76 - Loading models...
2024-09-16 22:10:37.298 | INFO | server.digital_human.modules.realtime_inference:init_digital_model:90 - Loaded models done !...
2024-09-16 22:10:37.319 | INFO | server.digital_human.modules.realtime_inference:init:246 - *********************************
2024-09-16 22:10:37.319 | INFO | server.digital_human.modules.realtime_inference:init:247 - creating avator: 1
2024-09-16 22:10:37.319 | INFO | server.digital_human.modules.realtime_inference:init:248 - *********************************
2024-09-16 22:10:37.378 | INFO | server.digital_human.modules.realtime_inference:prepare_material:265 - preparing data materials ... ...
2024-09-16 22:10:40.732 | INFO | server.digital_human.modules.realtime_inference:prepare_material:280 - extracting landmarks...
Loads checkpoint by local backend from path: weights/digital_human_weights/dwpose/dw-ll_ucoco_384.pth
reading images...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 47/47 [00:00<00:00, 48.82it/s]
get key_landmark and face bounding boxes with the default value
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 47/47 [00:12<00:00, 3.75it/s]
********************************************bbox_shift parameter adjustment**********************************************************
Total frame:「47」 Manually adjust range : [ -17~16 ] , the current value: 0
*************************************************************************************************************************************
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 94/94 [00:11<00:00, 8.40it/s]
reading images...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 94/94 [00:02<00:00, 38.87it/s]
reading images...
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 94/94 [00:00<00:00, 211.39it/s]
2024-09-16 22:11:21.518 | INFO | server.digital_human.modules.realtime_inference:setup_ffmpeg_env:51 - setting ffmpeg dir: /root/Streamer-Sales/weights/digital_human_weights/drivers/ffmpeg-7.0.2-amd64-static
2024-09-16 22:11:21.519 | INFO | server.digital_human.modules.realtime_inference:setup_ffmpeg_env:53 - add ffmpeg to path : /root/Streamer-Sales/weights/digital_human_weights/drivers/ffmpeg-7.0.2-amd64-static
INFO: Started server process [87210]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8002 (Press CTRL+C to quit)
3、sh deploy.sh asr : ASR服务 Uvicorn running on http://0.0.0.0:8003
正在启动 ASR 服务...
2024-09-16 22:10:29,155 - modelscope - INFO - PyTorch version 2.1.2 Found.
2024-09-16 22:10:29,160 - modelscope - INFO - Loading ast index from ./weights/asr_weights/ast_indexer
2024-09-16 22:10:34,517 - modelscope - INFO - Updating the files for the changes of local files, first time updating will take longer time! Please wait till updating done!
2024-09-16 22:10:34,526 - modelscope - INFO - AST-Scanning the path "/root/.conda/envs/streamer-sales/lib/python3.10/site-packages/modelscope" with the following sub folders ['models', 'metrics', 'pipelines', 'preprocessors', 'trainers', 'msdatasets', 'exporters']
2024-09-16 22:10:51,738 - modelscope - INFO - Scanning done! A number of 976 components indexed or updated! Time consumed 17.211905002593994s
2024-09-16 22:10:52,614 - modelscope - INFO - Loading done! Current index file version is 1.14.0, with md5 84061df8820ac16ae3d4705997314465 and a total number of 976 components indexed
downloading asr model : iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
2024-09-16 22:10:54,080 - modelscope - WARNING - Using the master branch is fragile, please use it with caution!
2024-09-16 22:10:54,080 - modelscope - INFO - Use user-specified model revision: master
downloading asr model : iic/speech_fsmn_vad_zh-cn-16k-common-pytorch
2024-09-16 22:10:54,796 - modelscope - WARNING - Using the master branch is fragile, please use it with caution!
2024-09-16 22:10:54,796 - modelscope - INFO - Use user-specified model revision: master
downloading asr model : iic/punc_ct-transformer_cn-en-common-vocab471067-large
2024-09-16 22:10:55,348 - modelscope - WARNING - Using the master branch is fragile, please use it with caution!
2024-09-16 22:10:55,348 - modelscope - INFO - Use user-specified model revision: master
ASR model path info = {'paraformer-zh': './weights/asr_weights/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch', 'fsmn-vad': './weights/asr_weights/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch', 'ct-punc': './weights/asr_weights/iic/punc_ct-transformer_cn-en-common-vocab471067-large'}
ckpt: ./weights/asr_weights/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/model.pt
ckpt: ./weights/asr_weights/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch/model.pt
Building prefix dict from the default dictionary ...
DEBUG:jieba:Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
DEBUG:jieba:Loading model from cache /tmp/jieba.cache
Loading model cost 2.635 seconds.
DEBUG:jieba:Loading model cost 2.635 seconds.
Prefix dict has been built successfully.
DEBUG:jieba:Prefix dict has been built successfully.
ckpt: ./weights/asr_weights/iic/punc_ct-transformer_cn-en-common-vocab471067-large/model.pt
INFO: Started server process [88134]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8003 (Press CTRL+C to quit)
4、sh deploy.sh llm : LLM 服务 Uvicorn running on http://0.0.0.0:23333
正在启动 LLM 服务...
2024-09-16 22:10:39,002 - modelscope - INFO - PyTorch version 2.1.2 Found.
2024-09-16 22:10:39,003 - modelscope - INFO - Loading ast index from ./weights/llm_weights/ast_indexer
2024-09-16 22:10:40,020 - modelscope - INFO - Updating the files for the changes of local files, first time updating will take longer time! Please wait till updating done!
2024-09-16 22:10:40,030 - modelscope - INFO - AST-Scanning the path "/root/.conda/envs/streamer-sales/lib/python3.10/site-packages/modelscope" with the following sub folders ['models', 'metrics', 'pipelines', 'preprocessors', 'trainers', 'msdatasets', 'exporters']
2024-09-16 22:10:56,186 - modelscope - INFO - Scanning done! A number of 976 components indexed or updated! Time consumed 16.156379461288452s
2024-09-16 22:10:57,002 - modelscope - INFO - Loading done! Current index file version is 1.14.0, with md5 84061df8820ac16ae3d4705997314465 and a total number of 976 components indexed
[WARNING] gemm_config.in is not found; using default GEMM algo
HINT: Please open http://0.0.0.0:23333 in a browser for detailed api usage!!!
HINT: Please open http://0.0.0.0:23333 in a browser for detailed api usage!!!
HINT: Please open http://0.0.0.0:23333 in a browser for detailed api usage!!!
INFO: Started server process [89419]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:23333 (Press CTRL+C to quit)
5、sh deploy.sh base : 中台服务 Uvicorn running on http://0.0.0.0:8000 (提示需要安装 : pip install sse_starlette)
如果启动报错找不到PRODUCT_INFO_YAML_PATH,需要在web_configs.py中配置文件路径中添加下面这一行,并复制文件product_info.yaml到configs文件夹。
PRODUCT_INFO_YAML_PATH: str = r"./configs/product_info.yaml" # 商品信息 (kfh 20240918 来自0.8版, 还需要复制0.8版的product_info.yaml到configs文件夹)。
如果启动时报错:File "/root/.conda/envs/streamer-sales/lib/python3.10/site-packages/psycopg/pq/__init__.py", line 110, in import_from_libpq
raise ImportError(
ImportError: no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary'
- couldn't import psycopg 'python' implementation: libpq library not found
错误提示表明缺少 PostgreSQL 客户端库 libpq
。psycopg
依赖于这个库来与 PostgreSQL 数据库交互。如果没有找到 libpq
,就会出现这个错误。
apt-get update
apt-get install libpq-dev
通过psql --version 发现PostgreSQL 未安装,可以运行以下命令进行安装:
apt-get install postgresql
export LIBPQ_DIR=/usr/local/pgsql
export LD_LIBRARY_PATH=/usr/lib/postgresql/12.20/lib #12.20为pg的版本号
查看版本psql --version: psql (PostgreSQL) 12.20 (Ubuntu 12.20-0ubuntu0.20.04.1)
service postgresql start
运行service postgresql status发现结果是online。
重新运行sh deploy.py base, 报错:
sqlalchemy.exc.OperationalError: (psycopg.OperationalError) connection failed: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "postgres"
connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "postgres"
(Background on this error at: https://sqlalche.me/e/20/e3q8)
修改 PostgreSQL 的认证配置文件 pg_hba.conf
,将 所有的md5
(密码认证方式)更改为 trust
(无需密码验证),这将允许本地用户在不需要密码的情况下登录。(pg_hba.conf
文件通常位于 /etc/postgresql/12/main/pg_hba.conf
(具体路径取决于 PostgreSQL 的版本和安装方式))
需要重启pg: service postgresql restart
再报错:psql: error: FATAL: database "streamer_sales_db" does not exist
从错误信息 FATAL: database "streamer_sales_db" does not exist
可以看出,PostgreSQL 数据库 streamer_sales_db
还没有被创建。
连接到 PostgreSQL(不指定数据库):psql -U postgres -h 127.0.0.1
在 psql
提示符下,运行以下 SQL 命令来创建数据库:CREATE DATABASE streamer_sales_db;
输入 \q
退出 psql。
现在可以连接到数据库streamer_sales_db了。
base后台运行成功后如下:
6、sh deploy.sh frontend : 前端服务 (提示需要安装 npm):
apt-get update
apt-get install nodejs
apt-get install npm
启动前端服务时报错vite:
npm config set registry http://registry.npm.taobao.org
npm install -g vite
安装成功后,但启动前端服务时,还是报错(node v10.19.0, npm v6.14.4):
更新node和npm(node v20.17.0,npm v10.8.2):
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
nvm -v
NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install v20.17.0
有报错缺少插件,安装:
npm install @vitejs/plugin-vue --save-dev
npm install vite-plugin-vue-devtools --save-dev
npm install @tsconfig/node20 --save-dev
npm install @vue/tsconfig --save-dev
/root/Streamer-Sales/frontend/src/components/lineChartComponent.vue 更改文件名为LineChartComponent.vue,barChartComponent更改文件名为BarChartComponent不知道为什么变成小写了。
又提示缺少依赖包,安装一下:
Error: The following dependencies are imported but could not be resolved:
pinia (imported by /root/Streamer-Sales/frontend/src/stores/userToken.ts)
pinia-plugin-persistedstate (imported by /root/Streamer-Sales/frontend/src/main.ts)
element-plus (imported by /root/Streamer-Sales/frontend/src/components/StreamerInfoComponent.vue?id=0)
element-plus/dist/index.css (imported by /root/Streamer-Sales/frontend/src/main.ts)
element-plus/es/locale/lang/zh-cn (imported by /root/Streamer-Sales/frontend/src/main.ts)
xgplayer/dist/index.min.css (imported by /root/Streamer-Sales/frontend/src/main.ts)
vue-router (imported by /root/Streamer-Sales/frontend/src/components/BreadCrumb.vue?id=0)
element-plus/es (imported by /root/Streamer-Sales/frontend/src/views/product/ProductEditView.vue?id=0)
@vueuse/core (imported by /root/Streamer-Sales/frontend/src/views/home/HomeView.vue?id=0)
axios (imported by /root/Streamer-Sales/frontend/src/components/InfoDialogComponents.vue?id=0)
@element-plus/icons-vue (imported by /root/Streamer-Sales/frontend/src/components/NavbarComponent.vue?id=0)
echarts (imported by /root/Streamer-Sales/frontend/src/components/BarChartComponent.vue?id=0)
md-editor-v3/lib/preview.css (imported by /root/Streamer-Sales/frontend/src/components/InfoDialogComponents.vue?id=0)
md-editor-v3 (imported by /root/Streamer-Sales/frontend/src/components/InfoDialogComponents.vue?id=0)
xgplayer (imported by /root/Streamer-Sales/frontend/src/components/VideoComponent.vue?id=0)
Are they installed?
前端运行成功后:
全部服务运行后GPU大约39G,使用默认账号密码登陆后,界面如下:
结语
到这里,整个项目已经实战完了,但由于环境问题,比如没有sudo权限,严格的说没有完全跑起来。下一步准备有时间租用云服务器完整的跑一遍。本项目属于PeterH0323的一个学习项目,本文仅仅复现实操了一部分,并将过程记录下来,并不能算是原创,再次感谢PeterH0323。
PeterH0323将本项目全部代码均已开源,大家可以过去看看,如果觉得项目做的不错,请帮作者点个 star ⭐,再次附上地址: https://github.com/PeterH0323/Streamer-Sales