{"id":14618,"date":"2025-04-18T21:18:34","date_gmt":"2025-04-18T13:18:34","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/14618.html"},"modified":"2025-04-18T21:18:34","modified_gmt":"2025-04-18T13:18:34","slug":"%e9%98%bf%e9%87%8c%e5%a3%b0%e9%9f%b3%e9%a1%b9%e7%9b%aeqwen2-audio%e7%9a%84%e9%83%a8%e7%bd%b2%e5%ae%89%e8%a3%85%ef%bc%8c%e5%9c%a8%e6%9c%8d%e5%8a%a1%e5%99%a8ubuntu22-04%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/14618.html","title":{"rendered":"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280"},"content":{"rendered":"<\/p>\n<h4>\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5&#xff0c;\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280<\/h4>\n<ul>\n<li>\u4e00\u3001ubuntu22.04\u57fa\u672c\u73af\u5883\u914d\u7f6e<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>1.1 \u66f4\u6362\u6e05\u534eUbuntu\u955c\u50cf\u6e90<\/li>\n<li>1.2 \u66f4\u65b0\u5305\u5217\u8868&#xff1a;<\/li>\n<li>2. \u5b89\u88c5\u82f1\u4f1f\u8fbe\u663e\u5361\u9a71\u52a8<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>2.1 \u4f7f\u7528wget\u5728\u547d\u4ee4\u884c\u4e0b\u8f7d\u9a71\u52a8\u5305<\/li>\n<li>2.2 \u66f4\u65b0\u8f6f\u4ef6\u5217\u8868\u548c\u5b89\u88c5\u5fc5\u8981\u8f6f\u4ef6\u3001\u4f9d\u8d56<\/li>\n<li>2.2 \u5378\u8f7d\u539f\u6709\u9a71\u52a8<\/li>\n<li>2.3 \u5b89\u88c5\u9a71\u52a8<\/li>\n<li>2.4 \u5b89\u88c5CUDA<\/li>\n<li>2.5 \u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4e8c\u3001\u5b89\u88c5miniconda\u73af\u5883<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>1. \u4e0b\u8f7dminiconda3<\/li>\n<li>2. \u5b89\u88c5miniconda3<\/li>\n<li>3. \u5207\u6362\u5230bin\u6587\u4ef6\u5939<\/li>\n<li>4. \u8f93\u5165pwd\u83b7\u53d6\u8def\u5f84<\/li>\n<li>5. \u6253\u5f00\u7528\u6237\u73af\u5883\u7f16\u8f91\u9875\u9762<\/li>\n<li>6. \u91cd\u65b0\u52a0\u8f7d\u7528\u6237\u73af\u5883\u53d8\u91cf<\/li>\n<li>7. \u521d\u59cb\u5316conda<\/li>\n<li>8.\u9a8c\u8bc1\u662f\u5426\u5b89\u88c5\u6210\u529f<\/li>\n<li>9.conda\u914d\u7f6e<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001\u5b89\u88c5Qwen2-Audio<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>1.\u514b\u9686\u4ed3\u5e93<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>1.1 github\u514b\u9686<\/li>\n<li>1.2 \u56fd\u5185github\u955c\u50cf\u514b\u9686<\/li>\n<li>1.3. \u8fdb\u5165\u76ee\u5f55<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>2.\u521b\u5efa\u865a\u62df\u73af\u5883<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>2.1 \u8fdb\u5165\u865a\u62df\u73af\u5883<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>3. \u5b89\u88c5\u4f9d\u8d56<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>3.1\u8bbe\u7f6e\u6e05\u534e\u6e90\u3001\u66f4\u65b0pip<\/li>\n<li>3.2\u5b89\u88c5torch 12.4cuda\u7248\u672c<\/li>\n<li>3.3\u5b89\u88c5\u4f9d\u8d56\u6587\u4ef6<\/li>\n<li>3.4\u5b89\u88c5webui\u754c\u9762\u53ca\u5176\u4ed6\u672a\u5b89\u88c5\u4f9d\u8d56<\/li>\n<li>3.5\u5b89\u88c5\u9b54\u642d\u5e93\u51c6\u5907\u4e0b\u8f7d\u6a21\u578b\u6587\u4ef6&#xff1a;<\/li>\n<li>3.6\u4e0b\u8f7d\u76f8\u5173\u6a21\u578b<\/li>\n<li>3.7\u6267\u884c\u4ee3\u7801&#xff0c;\u542f\u52a8webui\u754c\u9762<\/li>\n<li>3.8\u52a0\u5165\u58f0\u97f3\u9a71\u52a8&#xff0c;\u5b9e\u73b0\u771f\u6b63\u7684\u8bed\u97f3\u804a\u5929<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u56db\u3001\u6210\u529f\u5b9e\u73b0\u8bed\u97f3\u4ea4\u4e92<\/li>\n<li>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li>4.1 \u627e\u4e0d\u5230\u5f55\u97f3\u673a\u95ee\u9898<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e00\u3001ubuntu22.04\u57fa\u672c\u73af\u5883\u914d\u7f6e<\/h2>\n<h4>1.1 \u66f4\u6362\u6e05\u534eUbuntu\u955c\u50cf\u6e90<\/h4>\n<ul>\n<li>\u5220\u9664\u539f\u6765\u7684\u6587\u4ef6<\/li>\n<\/ul>\n<p>rm \/etc\/apt\/sources.list<\/p>\n<ul>\n<li>\u5f00\u59cb\u7f16\u8f91\u65b0\u6587\u4ef6<\/li>\n<\/ul>\n<p>vim \/etc\/apt\/sources.list<\/p>\n<ul>\n<li>\u5148\u6309i\u952e&#xff0c;\u7c98\u8d34\u4ee5\u4e0b\u5185\u5bb9<\/li>\n<\/ul>\n<p># \u9ed8\u8ba4\u6ce8\u91ca\u4e86\u6e90\u7801\u955c\u50cf\u4ee5\u63d0\u9ad8 apt update \u901f\u5ea6&#xff0c;\u5982\u6709\u9700\u8981\u53ef\u81ea\u884c\u53d6\u6d88\u6ce8\u91ca<br \/>\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy main restricted universe multiverse<br \/>\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy main restricted universe multiverse<br \/>\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy-updates main restricted universe multiverse<br \/>\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy-updates main restricted universe multiverse<br \/>\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy-backports main restricted universe multiverse<br \/>\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy-backports main restricted universe multiverse<\/p>\n<p># \u4ee5\u4e0b\u5b89\u5168\u66f4\u65b0\u8f6f\u4ef6\u6e90\u5305\u542b\u4e86\u5b98\u65b9\u6e90\u4e0e\u955c\u50cf\u7ad9\u914d\u7f6e&#xff0c;\u5982\u6709\u9700\u8981\u53ef\u81ea\u884c\u4fee\u6539\u6ce8\u91ca\u5207\u6362<br \/>\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy-security main restricted universe multiverse<br \/>\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu\/ jammy-security main restricted universe multiverse<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-6802512731b91.png\" alt=\"\u8bf7\u6dfb\u52a0\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\n<p>\u786e\u4fdd\u5185\u5bb9\u8ddf\u4e0a\u8ff0\u56fe\u7247\u4e00\u81f4<\/p>\n<\/li>\n<li>\n<p>\u6309esc\u952e&#xff0c;\u518d\u8f93\u5165\u5192\u53f7&#043;wq\u4fdd\u5b58<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-680251274d79d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>1.2 \u66f4\u65b0\u5305\u5217\u8868&#xff1a;<\/h4>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef&#xff0c;\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/li>\n<\/ul>\n<p>sudo apt-get update<\/p>\n<p>sudo apt upgrade<\/p>\n<ul>\n<li>\u66f4\u65b0\u65f6\u95f4\u8f83\u957f&#xff0c;\u8bf7\u8010\u5fc3\u7b49\u5f85<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-680251276ef69.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>2. \u5b89\u88c5\u82f1\u4f1f\u8fbe\u663e\u5361\u9a71\u52a8<\/h4>\n<h6>2.1 \u4f7f\u7528wget\u5728\u547d\u4ee4\u884c\u4e0b\u8f7d\u9a71\u52a8\u5305<\/h6>\n<p>wget https:\/\/cn.download.nvidia.com\/XFree86\/Linux-x86_64\/550.100\/NVIDIA-Linux-x86_64-550.100.run<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-68025127902c4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>2.2 \u66f4\u65b0\u8f6f\u4ef6\u5217\u8868\u548c\u5b89\u88c5\u5fc5\u8981\u8f6f\u4ef6\u3001\u4f9d\u8d56<\/h6>\n<p>sudo apt-get install g&#043;&#043;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-68025127ac73e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-68025127c7a01.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u70b9\u51fb\u56de\u8f66enter\u5373\u53ef <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-68025127e439b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>sudo apt-get install gcc<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-680251280b32e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>sudo apt-get install make<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-680251281fe3c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-680251283c50b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u70b9\u51fb\u56de\u8f66enter\u5373\u53ef<\/p>\n<p>\u6210\u529f\u5b89\u88c5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-68025128583f5.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>2.2 \u5378\u8f7d\u539f\u6709\u9a71\u52a8<\/h6>\n<p>sudo apt-get remove &#8211;purge nvidia* <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-680251287296e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>1.\u4f7f\u7528vim\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ul>\n<p>sudo vim \/etc\/modprobe.d\/blacklist.conf<\/p>\n<ul>\n<li>2.\u6309i\u952e\u8fdb\u5165\u7f16\u8f91\u6a21\u5f0f,\u5728\u6587\u4ef6\u5c3e\u589e\u52a0\u4e24\u884c&#xff1a;<\/li>\n<\/ul>\n<p>blacklist nouveau<br \/>\noptions nouveau modeset&#061;0<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-6802512893500.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\n<p>3.\u6309esc\u952e\u9000\u51fa\u7f16\u8f91\u6a21\u5f0f,\u8f93\u5165:wq\u4fdd\u5b58\u5e76\u9000\u51fa<\/p>\n<\/li>\n<li>\n<p>4.\u66f4\u65b0\u6587\u4ef6<\/p>\n<\/li>\n<\/ul>\n<p>sudo update-initramfs -u<\/p>\n<p>\u8fd9\u91cc\u7b49\u5f85\u65f6\u95f4\u8f83\u4e45<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-68025128af5fd.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>5.\u91cd\u542f\u7535\u8111&#xff1a;<\/li>\n<\/ul>\n<p>sudo reboot<\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u7b49\u4e00\u4f1a\u624d\u80fd\u8fde\u4e0a<\/p>\n<h6>2.3 \u5b89\u88c5\u9a71\u52a8<\/h6>\n<ul>\n<li>1.\u6388\u4e88\u6267\u884c\u6743\u9650<\/li>\n<\/ul>\n<p>sudo chmod 777 NVIDIA-Linux-x86_64-550.100.run<\/p>\n<ul>\n<li>2.\u6267\u884c\u5b89\u88c5\u547d\u4ee4<\/li>\n<\/ul>\n<p>sudo .\/NVIDIA-Linux-x86_64-550.100.run<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-68025128c07c4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-68025128db07a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u8fd9\u91cc\u4e00\u76f4\u6309\u56de\u8f66\u5c31\u884c&#xff0c;\u9ed8\u8ba4\u9009\u62e9<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131832-68025128f12b5.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131833-6802512911ec5.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131833-68025129269fe.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131833-680251293e1fa.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"2025-04-18c3jsmfz2fjx.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e00\u76f4\u6309\u56de\u8f66enter\u952e&#xff0c;\u76f4\u5230\u5b89\u88c5\u6210\u529f<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18t404lbnx3sr.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"2025-04-180i2blkrdsgy.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>3.\u68c0\u6d4b\u663e\u5361\u9a71\u52a8\u662f\u5426\u5b89\u88c5\u6210\u529f<\/li>\n<\/ul>\n<p>nvidia-smi<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18z1zi4ymqj45.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>2.4 \u5b89\u88c5CUDA<\/h6>\n<p>wget https:\/\/developer.download.nvidia.com\/compute\/cuda\/12.4.0\/local_installers\/cuda_12.4.0_550.54.14_linux.run<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18lwqhu3qtxqw.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6267\u884c\u5b89\u88c5\u547d\u4ee4<\/p>\n<p>sudo sh .\/cuda_12.4.0_550.54.14_linux.run<\/p>\n<ul>\n<li>1.\u8f93\u51faaccept\u5f00\u59cb\u5b89\u88c5<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"2025-04-18ovuhurbt0y1.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>2.\u7136\u540e\u6ce8\u610f\u8fd9\u91cc\u8981\u6309enter\u53d6\u6d88\u52fe\u9009\u7b2c\u4e00\u4e2a\u9009\u9879,\u56e0\u4e3a\u4e4b\u524d\u5df2\u7ecf\u5b89\u88c5\u4e86\u9a71\u52a8<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"2025-04-18hsk4y5dxbsc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>3.\u63a5\u7740\u9009\u62e9Install\u5f00\u59cb\u5b89\u88c5<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"2025-04-180uessvvxaqb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>4.\u5b89\u88c5\u5b8c\u6210<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"2025-04-18ljgcmnqkszz.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>2.5 \u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/h6>\n<ul>\n<li>1.\u4ee5vim\u65b9\u5f0f\u6253\u5f00\u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ul>\n<p>sudo vim ~\/.bashrc<\/p>\n<ul>\n<li>2.\u6309i\u952e\u8fdb\u5165\u7f16\u8f91\u6a21\u5f0f,\u5728\u6587\u4ef6\u5c3e\u589e\u52a0\u4e0b\u9762\u5185\u5bb9&#xff1a;<\/li>\n<\/ul>\n<p>export PATH&#061;&#034;\/usr\/local\/cuda-12.4\/bin:$PATH&#034;<br \/>\nexport LD_LIBRARY_PATH&#061;&#034;\/usr\/local\/cuda-12.4\/lib64:$LD_LIBRARY_PATH&#034;<\/p>\n<p><img decoding=\"async\" src=\"2025-04-184rsnwgdkziy.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\n<p>\u6309esc\u952e\u9000\u51fa\u7f16\u8f91\u6a21\u5f0f,\u8f93\u5165:wq\u4fdd\u5b58\u5e76\u9000\u51fa<\/p>\n<\/li>\n<li>\n<p>3.\u66f4\u65b0\u73af\u5883\u53d8\u91cf<\/p>\n<\/li>\n<\/ul>\n<p>source ~\/.bashrc<\/p>\n<ul>\n<li>4.\u68c0\u6d4bCUDA\u662f\u5426\u5b89\u88c5\u6210\u529f<\/li>\n<\/ul>\n<p>nvcc -V<\/p>\n<p><img decoding=\"async\" src=\"2025-04-180rroviefzeh.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e8c\u3001\u5b89\u88c5miniconda\u73af\u5883<\/h2>\n<h4>1. \u4e0b\u8f7dminiconda3<\/h4>\n<p>wget https:\/\/mirrors.cqupt.edu.cn\/anaconda\/miniconda\/Miniconda3-py310_23.10.0-1-Linux-x86_64.sh<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18zkj1upra10h.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>2. \u5b89\u88c5miniconda3<\/h4>\n<p>bash Miniconda3-py310_23.10.0-1-Linux-x86_64.sh -u<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18wf1f1rz1flq.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u76f4\u63a5\u4e00\u76f4enter\u952e&#xff0c;\u5230\u8f93\u5165\u8def\u5f84\u548cyes<\/p>\n<p>\u8fd9\u8fb9\u5efa\u8bae\u8def\u5f84\u4e3a&#xff1a;miniconda3<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18snkzrtd3pof.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u76f4\u63a5\u56de\u8f66enter\u5373\u53ef&#xff0c;\u518d\u6b21\u8f93\u5165yes<\/p>\n<p><img decoding=\"async\" src=\"2025-04-183egbabdk0s2.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6210\u529f\u5b89\u88c5<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18x1x5t2metpx.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>3. \u5207\u6362\u5230bin\u6587\u4ef6\u5939<\/h4>\n<p>cd miniconda3\/bin\/<\/p>\n<h4>4. \u8f93\u5165pwd\u83b7\u53d6\u8def\u5f84<\/h4>\n<p>pwd<\/p>\n<p>\u590d\u5236\u8fd9\u91cc\u7684\u8def\u5f84<\/p>\n<h4>5. \u6253\u5f00\u7528\u6237\u73af\u5883\u7f16\u8f91\u9875\u9762<\/h4>\n<p>vim ~\/.bashrc <\/p>\n<ul>\n<li>\u70b9\u51fb\u952e\u76d8I\u952e\u8fdb\u5165\u7f16\u8f91\u6a21\u5f0f&#xff0c;\u5728\u6700\u4e0b\u65b9\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801<\/li>\n<\/ul>\n<p>export PATH&#061;&#034;\/root\/miniconda3\/bin:$PATH&#034;<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18qqlchb11byh.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6309esc\u952e\u9000\u51fa\u7f16\u8f91\u6a21\u5f0f,\u8f93\u5165:wq\u4fdd\u5b58\u5e76\u9000\u51fa<\/p>\n<h4>6. \u91cd\u65b0\u52a0\u8f7d\u7528\u6237\u73af\u5883\u53d8\u91cf<\/h4>\n<p>source ~\/.bashrc<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18ibcl5j3dkhx.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>7. \u521d\u59cb\u5316conda<\/h4>\n<p>conda init bash<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18ui31coqldpp.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>8.\u9a8c\u8bc1\u662f\u5426\u5b89\u88c5\u6210\u529f<\/h4>\n<p>conda -V<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18spznb12jjrj.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>9.conda\u914d\u7f6e<\/h4>\n<ul>\n<li>\n<p>1.\u914d\u7f6e\u6e05\u534e\u955c\u50cf\u6e90<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<\/li>\n<\/ul>\n<p>conda config &#8211;add channels https:\/\/mirrors.tuna.tsinghua.edu.cn\/anaconda\/pkgs\/free\/<br \/>\nconda config &#8211;add channels https:\/\/mirrors.tuna.tsinghua.edu.cn\/anaconda\/pkgs\/main\/<br \/>\nconda config &#8211;add channels https:\/\/mirrors.tuna.tsinghua.edu.cn\/anaconda\/cloud\/conda-forge\/<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18bus3rectqw4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>2.\u8bbe\u7f6e\u641c\u7d22\u65f6\u663e\u793a\u901a\u9053\u5730\u5740<\/li>\n<\/ul>\n<p>conda config &#8211;set show_channel_urls yes<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18xntzuvn1anc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>3.\u914d\u7f6epip \u955c\u50cf\u6e90<\/li>\n<\/ul>\n<p>pip config set global.index-url https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18h0n4iw34lyz.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e09\u3001\u5b89\u88c5Qwen2-Audio<\/h2>\n<h4>1.\u514b\u9686\u4ed3\u5e93<\/h4>\n<h6>1.1 github\u514b\u9686<\/h6>\n<p>git clone https:\/\/github.com\/QwenLM\/Qwen2-Audio.git<\/p>\n<h6>1.2 \u56fd\u5185github\u955c\u50cf\u514b\u9686<\/h6>\n<p>git clone https:\/\/mirror.ghproxy.com\/https:\/\/github.com\/QwenLM\/Qwen2-Audio.git<\/p>\n<h6>1.3. \u8fdb\u5165\u76ee\u5f55<\/h6>\n<p>cd Qwen2-Audio\/<\/p>\n<h4>2.\u521b\u5efa\u865a\u62df\u73af\u5883<\/h4>\n<p>conda create -n qwen2 python&#061;3.10<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18wlo5arpdkx0.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\u8f93\u5165y\u56de\u8f66\u5373\u53ef<\/li>\n<\/ul>\n<h6>2.1 \u8fdb\u5165\u865a\u62df\u73af\u5883<\/h6>\n<p>conda activate qwen2<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18rex5gjmoczk.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>3. \u5b89\u88c5\u4f9d\u8d56<\/h4>\n<h6>3.1\u8bbe\u7f6e\u6e05\u534e\u6e90\u3001\u66f4\u65b0pip<\/h6>\n<p>pip config set global.index-url https:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n<p>python -m pip install &#8211;upgrade pip<\/p>\n<h6>3.2\u5b89\u88c5torch 12.4cuda\u7248\u672c<\/h6>\n<p>pip3 install torch torchvision torchaudio &#8211;index-url https:\/\/download.pytorch.org\/whl\/cu124<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18ddocmtrgxvi.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>3.3\u5b89\u88c5\u4f9d\u8d56\u6587\u4ef6<\/h6>\n<p>cd demo<\/p>\n<p>pip install -r requirements_web_demo.txt<\/p>\n<h6>3.4\u5b89\u88c5webui\u754c\u9762\u53ca\u5176\u4ed6\u672a\u5b89\u88c5\u4f9d\u8d56<\/h6>\n<p>pip install librosa<\/p>\n<p>pip install &#8211;upgrade &#034;accelerate&gt;&#061;0.21.0&#034;<\/p>\n<p>pip install django<\/p>\n<p>pip install git&#043;https:\/\/mirror.ghproxy.com\/https:\/\/github.com\/huggingface\/transformers<\/p>\n<h6>3.5\u5b89\u88c5\u9b54\u642d\u5e93\u51c6\u5907\u4e0b\u8f7d\u6a21\u578b\u6587\u4ef6&#xff1a;<\/h6>\n<p>pip install modelscope<\/p>\n<h6>3.6\u4e0b\u8f7d\u76f8\u5173\u6a21\u578b<\/h6>\n<p>cd ..<\/p>\n<p>modelscope download &#8211;model qwen\/qwen2-audio-7b-instruct &#8211;local_dir &#039;.\/Qwen\/Qwen2-Audio-7B-Instruct&#039;<\/p>\n<h6>3.7\u6267\u884c\u4ee3\u7801&#xff0c;\u542f\u52a8webui\u754c\u9762<\/h6>\n<ul>\n<li>\u6539\u7aef\u53e3<\/li>\n<\/ul>\n<p>vim demo\/web_demo_audio.py<\/p>\n<p>\u6309i\u8fdb\u884c\u7f16\u8f91&#xff0c;\u5b8c\u6210\u540e\u518d\u6309esc&#xff0c;\u5192\u53f7&#xff0c;wq\u9000\u51fa<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18uvz3yq5odt3.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\u6210\u529f\u8fdb\u5165<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"2025-04-18br5ypgqgrhm.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h6>3.8\u52a0\u5165\u58f0\u97f3\u9a71\u52a8&#xff0c;\u5b9e\u73b0\u771f\u6b63\u7684\u8bed\u97f3\u804a\u5929<\/h6>\n<p>cd demo<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684webui\u754c\u9762\u7684\u6587\u4ef6<\/li>\n<\/ul>\n<p>touch test_audio.py<\/p>\n<p>vim test_audio.py<\/p>\n<p>\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<p>import gradio as gr<br \/>\nimport modelscope_studio as mgr<br \/>\nimport librosa<br \/>\nfrom transformers import AutoProcessor, Qwen2AudioForConditionalGeneration<br \/>\nfrom argparse import ArgumentParser<br \/>\nimport requests<br \/>\nimport os<br \/>\nfrom django.http import HttpResponse<\/p>\n<p># \u9ed8\u8ba4\u7684\u6a21\u578b\u68c0\u67e5\u70b9\u8def\u5f84<br \/>\nDEFAULT_CKPT_PATH &#061; &#039;Qwen\/Qwen2-Audio-7B-Instruct&#039;<\/p>\n<p>def text_to_speech(text2):<br \/>\n    data &#061; {<br \/>\n        &#034;text&#034;: text2,<br \/>\n        &#034;text_language&#034;: &#034;zh&#034;,<br \/>\n    }<br \/>\n    # \u6ce8\u610f URL \u4e2d\u7684\u5355\u5f15\u53f7\u5e94\u8be5\u662f URL \u7684\u4e00\u90e8\u5206&#xff0c;\u9700\u8981\u6b63\u786e\u8f6c\u4e49<br \/>\n    response &#061; requests.post(&#039;http:\/\/\u670d\u52a1\u5668IP:\u7aef\u53e3&#039;, json&#061;data)<\/p>\n<p>    if response.status_code &#061;&#061; 200:<br \/>\n        audio_file_path &#061; &#034;\/root\/project\/Qwen2-Audio\/demo\/output.mp3&#034;<br \/>\n        with open(audio_file_path, &#034;wb&#034;) as f:<br \/>\n            f.write(response.content)<br \/>\n        return audio_file_path<br \/>\n    else:<br \/>\n        print(f&#034;\u9519\u8bef&#xff1a;\u8bf7\u6c42\u5931\u8d25&#xff0c;\u72b6\u6001\u7801\u4e3a {response.status_code}&#034;)<br \/>\n        return None<\/p>\n<p>def _get_args():<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570&#xff0c;\u83b7\u53d6\u8fd0\u884c\u914d\u7f6e\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        argparse.Namespace: \u5305\u542b\u547d\u4ee4\u884c\u53c2\u6570\u7684\u547d\u540d\u7a7a\u95f4\u5bf9\u8c61\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    parser &#061; ArgumentParser()<br \/>\n    parser.add_argument(&#034;-c&#034;, &#034;&#8211;checkpoint-path&#034;, type&#061;str, default&#061;DEFAULT_CKPT_PATH,<br \/>\n                        help&#061;&#034;Checkpoint name or path, default to %(default)r&#034;)  # \u6a21\u578b\u68c0\u67e5\u70b9\u8def\u5f84<br \/>\n    parser.add_argument(&#034;&#8211;cpu-only&#034;, action&#061;&#034;store_true&#034;, help&#061;&#034;Run demo with CPU only&#034;)  # \u662f\u5426\u4ec5\u4f7f\u7528CPU<br \/>\n    parser.add_argument(&#034;&#8211;inbrowser&#034;, action&#061;&#034;store_true&#034;, default&#061;False,<br \/>\n                        help&#061;&#034;Automatically launch the interface in a new tab on the default browser.&#034;)  # \u662f\u5426\u5728\u6d4f\u89c8\u5668\u4e2d\u81ea\u52a8\u6253\u5f00\u754c\u9762<br \/>\n    parser.add_argument(&#034;&#8211;server-port&#034;, type&#061;int, default&#061;15110,<br \/>\n                        help&#061;&#034;Demo server port.&#034;)  # \u6307\u5b9a\u670d\u52a1\u5668\u7aef\u53e3<br \/>\n    parser.add_argument(&#034;&#8211;server-name&#034;, type&#061;str, default&#061;&#034;0.0.0.0&#034;,<br \/>\n                        help&#061;&#034;Demo server name.&#034;)  # \u6307\u5b9a\u670d\u52a1\u5668\u540d\u79f0<\/p>\n<p>    args &#061; parser.parse_args()<br \/>\n    return args<\/p>\n<p>def add_text(chatbot, task_history, input):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u5c06\u7528\u6237\u8f93\u5165\u7684\u6587\u672c\u5185\u5bb9\u6dfb\u52a0\u5230\u804a\u5929\u8bb0\u5f55\u4e2d&#xff0c;\u5e76\u66f4\u65b0\u804a\u5929\u673a\u5668\u4eba\u754c\u9762\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        chatbot (gr.components.Chatbot): \u804a\u5929\u673a\u5668\u4eba\u7ec4\u4ef6\u3002<br \/>\n        task_history (list): \u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<br \/>\n        input (gr.inputs): \u7528\u6237\u8f93\u5165\u5185\u5bb9\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        tuple: \u66f4\u65b0\u540e\u7684\u804a\u5929\u673a\u5668\u4eba\u754c\u9762\u548c\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55&#xff0c;\u4ee5\u53ca\u91cd\u7f6e\u540e\u7684\u7528\u6237\u8f93\u5165\u6846\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    text_content &#061; input.text  # \u83b7\u53d6\u6587\u672c\u8f93\u5165\u5185\u5bb9<br \/>\n    content &#061; []<br \/>\n    if len(input.files) &gt; 0:  # \u5982\u679c\u7528\u6237\u4e0a\u4f20\u4e86\u97f3\u9891\u6587\u4ef6<br \/>\n        for i in input.files:<br \/>\n            content.append({&#039;type&#039;: &#039;audio&#039;, &#039;audio_url&#039;: i.path})  # \u5c06\u97f3\u9891\u6587\u4ef6\u6dfb\u52a0\u5230\u5185\u5bb9\u5217\u8868\u4e2d<br \/>\n    if text_content:  # \u5982\u679c\u7528\u6237\u8f93\u5165\u4e86\u6587\u672c<br \/>\n        content.append({&#039;type&#039;: &#039;text&#039;, &#039;text&#039;: text_content})  # \u5c06\u6587\u672c\u5185\u5bb9\u6dfb\u52a0\u5230\u5185\u5bb9\u5217\u8868\u4e2d<br \/>\n    task_history.append({&#034;role&#034;: &#034;user&#034;, &#034;content&#034;: content})  # \u66f4\u65b0\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55<\/p>\n<p>    # \u66f4\u65b0\u804a\u5929\u673a\u5668\u4eba\u754c\u9762&#xff0c;\u6dfb\u52a0\u7528\u6237\u8f93\u5165<br \/>\n    chatbot.append([{<br \/>\n        &#034;text&#034;: input.text,<br \/>\n        &#034;files&#034;: input.files,<br \/>\n    }, None])<br \/>\n    return chatbot, task_history, None<br \/>\n&#039;&#039;&#039;<br \/>\ndef add_file(chatbot, task_history, audio_file_path):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u5c06\u97f3\u9891\u6587\u4ef6\u6dfb\u52a0\u5230\u804a\u5929\u8bb0\u5f55\u4e2d\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        chatbot (gr.components.Chatbot): \u804a\u5929\u673a\u5668\u4eba\u7ec4\u4ef6\u3002<br \/>\n        task_history (list): \u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<br \/>\n        audio_file_path (str): \u97f3\u9891\u6587\u4ef6\u7684\u8def\u5f84\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        tuple: \u66f4\u65b0\u540e\u7684\u804a\u5929\u673a\u5668\u4eba\u754c\u9762\u548c\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    # \u786e\u4fdd\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u4e2d\u7684\u97f3\u9891\u6761\u76ee\u662f\u6b63\u786e\u7684\u683c\u5f0f<br \/>\n    task_history.append({&#034;role&#034;: &#034;user&#034;, &#034;content&#034;: [{&#034;type&#034;: &#034;audio&#034;, &#034;audio_url&#034;: audio_file_path}]})<\/p>\n<p>    # \u66f4\u65b0\u804a\u5929\u8bb0\u5f55&#xff0c;\u76f4\u63a5\u4f7f\u7528 audio_file_path \u800c\u4e0d\u662f gr.Audio \u7ec4\u4ef6<br \/>\n    chatbot.append((None, {&#034;type&#034;: &#034;audio&#034;, &#034;audio_url&#034;: audio_file_path}))<\/p>\n<p>    return chatbot, task_history<br \/>\n&#039;&#039;&#039;<br \/>\nimport os<\/p>\n<p>def add_file(chatbot, task_history, audio_path):<br \/>\n    if not os.path.isfile(audio_path):<br \/>\n        print(f&#034;Error: The file {audio_path} does not exist.&#034;)<br \/>\n        return chatbot, task_history<\/p>\n<p>    # \u5c06\u97f3\u9891\u6587\u4ef6\u4fe1\u606f\u6dfb\u52a0\u5230\u4efb\u52a1\u5386\u53f2<br \/>\n    task_history.append({<br \/>\n        &#034;role&#034;: &#034;user&#034;,<br \/>\n        &#034;content&#034;: [{&#034;type&#034;: &#034;audio&#034;, &#034;audio_url&#034;: audio_path}]<br \/>\n    })<\/p>\n<p>    # \u5047\u8bbe chatbot \u7ec4\u4ef6\u53ef\u4ee5\u63a5\u53d7\u5b57\u5178\u683c\u5f0f\u7684\u8f93\u5165<br \/>\n    chatbot_state &#061; [{<br \/>\n        &#034;text&#034;: f&#034;[Audio file: {os.path.basename(audio_path)}]&#034;,<br \/>\n        &#034;files&#034;: [audio_path]  # \u76f4\u63a5\u4f7f\u7528\u6587\u4ef6\u8def\u5f84\u800c\u4e0d\u662f gr.File<br \/>\n    }, None]<br \/>\n    chatbot.append(chatbot_state)  # \u66f4\u65b0 chatbot \u72b6\u6001<\/p>\n<p>    return chatbot, task_history<\/p>\n<p>def reset_user_input():<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u91cd\u7f6e\u7528\u6237\u8f93\u5165\u5b57\u6bb5\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        gr.update: \u5c06\u6587\u672c\u6846\u7684\u503c\u91cd\u7f6e\u4e3a\u7a7a\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    return gr.Textbox.update(value&#061;&#039;&#039;)<\/p>\n<p>def reset_state(task_history):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u91cd\u7f6e\u804a\u5929\u8bb0\u5f55\u548c\u4efb\u52a1\u5386\u53f2\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        task_history (list): \u5f53\u524d\u7684\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        tuple: \u6e05\u7a7a\u7684\u804a\u5929\u8bb0\u5f55\u548c\u4efb\u52a1\u5386\u53f2\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    return [], []<\/p>\n<p>def regenerate(chatbot, task_history):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u91cd\u65b0\u751f\u6210\u6700\u540e\u7684\u673a\u5668\u4eba\u54cd\u5e94\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        chatbot (gr.components.Chatbot): \u804a\u5929\u673a\u5668\u4eba\u7ec4\u4ef6\u3002<br \/>\n        task_history (list): \u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        tuple: \u66f4\u65b0\u540e\u7684\u804a\u5929\u673a\u5668\u4eba\u754c\u9762\u548c\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    # \u5982\u679c\u6700\u540e\u4e00\u6761\u6d88\u606f\u662f\u52a9\u624b\u751f\u6210\u7684&#xff0c;\u5219\u79fb\u9664\u5b83<br \/>\n    if task_history and task_history[-1][&#039;role&#039;] &#061;&#061; &#039;assistant&#039;:<br \/>\n        task_history.pop()<br \/>\n        chatbot.pop()<br \/>\n    # \u5982\u679c\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u4e0d\u4e3a\u7a7a&#xff0c;\u91cd\u65b0\u751f\u6210\u54cd\u5e94<br \/>\n    if task_history:<br \/>\n        chatbot, task_history &#061; predict(chatbot, task_history)<br \/>\n    return chatbot, task_history<\/p>\n<p>def predict(chatbot, task_history):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u6839\u636e\u5f53\u524d\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u751f\u6210\u6a21\u578b\u54cd\u5e94&#xff0c;\u5e76\u5c06\u54cd\u5e94\u8f6c\u6362\u4e3a\u97f3\u9891\u6587\u4ef6\u6dfb\u52a0\u5230\u804a\u5929\u8bb0\u5f55\u4e2d\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        chatbot (gr.components.Chatbot): \u804a\u5929\u673a\u5668\u4eba\u7ec4\u4ef6\u3002<br \/>\n        task_history (list): \u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n<p>    \u8fd4\u56de:<br \/>\n        tuple: \u66f4\u65b0\u540e\u7684\u804a\u5929\u673a\u5668\u4eba\u754c\u9762\u548c\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    print(f&#034;{task_history&#061;}&#034;)<br \/>\n    print(f&#034;{chatbot&#061;}&#034;)<\/p>\n<p>    # \u4f7f\u7528\u5904\u7406\u5668\u5c06\u4efb\u52a1\u5386\u53f2\u8bb0\u5f55\u683c\u5f0f\u5316\u4e3a\u6a21\u578b\u8f93\u5165<br \/>\n    text &#061; processor.apply_chat_template(task_history, add_generation_prompt&#061;True, tokenize&#061;False)<br \/>\n    audios &#061; []<\/p>\n<p>    # \u904d\u5386\u4efb\u52a1\u5386\u53f2&#xff0c;\u67e5\u627e\u97f3\u9891\u5185\u5bb9\u5e76\u52a0\u8f7d<br \/>\n    for message in task_history:<br \/>\n        if isinstance(message[&#034;content&#034;], list):<br \/>\n            for ele in message[&#034;content&#034;]:<br \/>\n                if ele[&#034;type&#034;] &#061;&#061; &#034;audio&#034;:<br \/>\n                    audios.append(<br \/>\n                        librosa.load(ele[&#039;audio_url&#039;], sr&#061;processor.feature_extractor.sampling_rate)[0]<br \/>\n                    )<\/p>\n<p>    if len(audios) &#061;&#061; 0:  # \u5982\u679c\u6ca1\u6709\u97f3\u9891&#xff0c;\u5219\u8bbe\u7f6e\u4e3a None<br \/>\n        audios &#061; None<br \/>\n    print(f&#034;{text&#061;}&#034;)<br \/>\n    print(f&#034;{audios&#061;}&#034;)<\/p>\n<p>    # \u4f7f\u7528\u5904\u7406\u5668\u751f\u6210\u6a21\u578b\u8f93\u5165<br \/>\n    inputs &#061; processor(text&#061;text, audios&#061;audios, return_tensors&#061;&#034;pt&#034;, padding&#061;True)<br \/>\n    if not _get_args().cpu_only:  # \u5982\u679c\u652f\u6301 GPU&#xff0c;\u5219\u5c06\u8f93\u5165\u6570\u636e\u79fb\u52a8\u5230 CUDA \u8bbe\u5907<br \/>\n        inputs[&#034;input_ids&#034;] &#061; inputs.input_ids.to(&#034;cuda&#034;)<\/p>\n<p>    # \u751f\u6210\u54cd\u5e94<br \/>\n    generate_ids &#061; model.generate(**inputs, max_length&#061;256)<br \/>\n    generate_ids &#061; generate_ids[:, inputs.input_ids.size(1):]<\/p>\n<p>    # \u89e3\u7801\u751f\u6210\u7684\u6587\u672c\u54cd\u5e94<br \/>\n    # \u5047\u8bbe\u5176\u4ed6\u53c2\u6570\u5df2\u7ecf\u6b63\u786e\u8bbe\u7f6e<br \/>\n    response &#061; processor.batch_decode(generate_ids, skip_special_tokens&#061;True)[0]<br \/>\n    task_history.append({&#039;role&#039;: &#039;assistant&#039;, &#039;content&#039;: response})<br \/>\n    chatbot.append((None, response))  # \u6dfb\u52a0\u6587\u672c\u54cd\u5e94<\/p>\n<p>    # \u5c06\u6587\u672c\u54cd\u5e94\u8f6c\u6362\u4e3a\u8bed\u97f3<br \/>\n    audio_file_path &#061; text_to_speech(response)<br \/>\n    if audio_file_path:<br \/>\n        chatbot, task_history &#061; add_file(chatbot, task_history, audio_file_path)<\/p>\n<p>    return chatbot, task_history<\/p>\n<p>def _launch_demo(args):<br \/>\n    &#034;&#034;&#034;<br \/>\n    \u542f\u52a8Gradio\u7684Web\u7528\u6237\u754c\u9762&#xff0c;\u5c55\u793aQwen2-Audio-Instruct\u6a21\u578b\u7684\u804a\u5929\u529f\u80fd\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        args (argparse.Namespace): \u4ece\u547d\u4ee4\u884c\u89e3\u6790\u7684\u53c2\u6570\u3002<br \/>\n    &#034;&#034;&#034;<br \/>\n    with gr.Blocks() as demo:<br \/>\n        # \u6dfb\u52a0\u9875\u9762\u6807\u9898\u548c\u63cf\u8ff0<br \/>\n        gr.Markdown(<br \/>\n            &#034;&#034;&#034;&lt;p align&#061;&#034;center&#034;&gt;&lt;img src&#061;&#034;https:\/\/qianwen-res.oss-cn-beijing.aliyuncs.com\/assets\/blog\/qwenaudio\/qwen2audio_logo.png&#034; style&#061;&#034;height: 80px&#034;\/&gt;&lt;p&gt;&#034;&#034;&#034;)<br \/>\n        gr.Markdown(&#034;&#034;&#034;&lt;center&gt;&lt;font size&#061;8&gt;Qwen2-Audio-Instruct Bot&lt;\/center&gt;&#034;&#034;&#034;)<br \/>\n        gr.Markdown(<br \/>\n            &#034;&#034;&#034;\\\\<br \/>\n    &lt;center&gt;&lt;font size&#061;3&gt;This WebUI is based on Qwen2-Audio-Instruct, developed by Alibaba Cloud. \\\\<br \/>\n    (\u672cWebUI\u57fa\u4e8eQwen2-Audio-Instruct\u6253\u9020&#xff0c;\u5b9e\u73b0\u804a\u5929\u673a\u5668\u4eba\u529f\u80fd\u3002)&lt;\/center&gt;&#034;&#034;&#034;)<br \/>\n        gr.Markdown(&#034;&#034;&#034;\\\\<br \/>\n    &lt;center&gt;&lt;font size&#061;4&gt;Qwen2-Audio &lt;a href&#061;&#034;https:\/\/modelscope.cn\/models\/qwen\/Qwen2-Audio-7B&#034;&gt;&#x1f916; &lt;\/a&gt;<br \/>\n    | &lt;a href&#061;&#034;https:\/\/huggingface.co\/Qwen\/Qwen2-Audio-7B&#034;&gt;&#x1f917;&lt;\/a&gt;&amp;nbsp &#xff5c;<br \/>\n    Qwen2-Audio-Instruct &lt;a href&#061;&#034;https:\/\/modelscope.cn\/models\/qwen\/Qwen2-Audio-7B-Instruct&#034;&gt;&#x1f916; &lt;\/a&gt; |<br \/>\n    &lt;a href&#061;&#034;https:\/\/huggingface.co\/Qwen\/Qwen2-Audio-7B-Instruct&#034;&gt;&#x1f917;&lt;\/a&gt;&amp;nbsp &#xff5c;<br \/>\n    &amp;nbsp&lt;a href&#061;&#034;https:\/\/github.com\/QwenLM\/Qwen2-Audio&#034;&gt;Github&lt;\/a&gt;&lt;\/center&gt;&#034;&#034;&#034;)<\/p>\n<p>        # \u521b\u5efa\u804a\u5929\u673a\u5668\u4eba\u7ec4\u4ef6<br \/>\n        chatbot &#061; mgr.Chatbot(label&#061;&#039;Qwen2-Audio-7B-Instruct&#039;, elem_classes&#061;&#034;control-height&#034;, height&#061;750)<\/p>\n<p>        # \u521b\u5efa\u7528\u6237\u8f93\u5165\u7ec4\u4ef6&#xff0c;\u652f\u6301\u6587\u672c\u3001\u9ea6\u514b\u98ce\u548c\u6587\u4ef6\u4e0a\u4f20<br \/>\n        user_input &#061; mgr.MultimodalInput(<br \/>\n            interactive&#061;True,<br \/>\n            sources&#061;[&#039;microphone&#039;, &#039;upload&#039;],<br \/>\n            submit_button_props&#061;dict(value&#061;&#034;&#x1f680; Submit (\u53d1\u9001)&#034;),<br \/>\n            upload_button_props&#061;dict(value&#061;&#034;&#x1f4c1; Upload (\u4e0a\u4f20\u6587\u4ef6)&#034;, show_progress&#061;True),<br \/>\n        )<br \/>\n        task_history &#061; gr.State([])  # \u521d\u59cb\u5316\u4efb\u52a1\u5386\u53f2\u72b6\u6001<\/p>\n<p>        with gr.Row():  # \u521b\u5efa\u6e05\u9664\u5386\u53f2\u548c\u91cd\u8bd5\u6309\u94ae<br \/>\n            empty_bin &#061; gr.Button(&#034;&#x1f9f9; Clear History (\u6e05\u9664\u5386\u53f2)&#034;)<br \/>\n            regen_btn &#061; gr.Button(&#034;&#x1f914;\ufe0f Regenerate (\u91cd\u8bd5)&#034;)<\/p>\n<p>        # \u5f53\u7528\u6237\u63d0\u4ea4\u8f93\u5165\u65f6&#xff0c;\u8c03\u7528add_text\u51fd\u6570&#xff0c;\u7136\u540e\u8c03\u7528predict\u51fd\u6570\u751f\u6210\u54cd\u5e94<br \/>\n        user_input.submit(fn&#061;add_text,<br \/>\n                          inputs&#061;[chatbot, task_history, user_input],<br \/>\n                          outputs&#061;[chatbot, task_history, user_input]).then(<br \/>\n            predict, [chatbot, task_history], [chatbot, task_history], show_progress&#061;True<br \/>\n        )<br \/>\n        # \u6e05\u9664\u5386\u53f2\u6309\u94ae\u7684\u70b9\u51fb\u4e8b\u4ef6\u5904\u7406&#xff0c;\u91cd\u7f6e\u804a\u5929\u8bb0\u5f55\u548c\u4efb\u52a1\u5386\u53f2<br \/>\n        empty_bin.click(reset_state, outputs&#061;[chatbot, task_history], show_progress&#061;True)<br \/>\n        # \u91cd\u8bd5\u6309\u94ae\u7684\u70b9\u51fb\u4e8b\u4ef6\u5904\u7406&#xff0c;\u91cd\u65b0\u751f\u6210\u6700\u540e\u7684\u54cd\u5e94<br \/>\n        regen_btn.click(regenerate, [chatbot, task_history], [chatbot, task_history], show_progress&#061;True)<\/p>\n<p>    # \u542f\u52a8Gradio\u754c\u9762<br \/>\n    demo.queue().launch(<br \/>\n        share&#061;False,  # \u4e0d\u5171\u4eabURL<br \/>\n        inbrowser&#061;args.inbrowser,  # \u662f\u5426\u81ea\u52a8\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00<br \/>\n        server_port&#061;args.server_port,  # \u6307\u5b9a\u670d\u52a1\u5668\u7aef\u53e3<br \/>\n        server_name&#061;args.server_name,  # \u6307\u5b9a\u670d\u52a1\u5668\u540d\u79f0<br \/>\n        ssl_certfile&#061;&#034;\/root\/project\/cert.pem&#034;,<br \/>\n        ssl_keyfile&#061;&#034;\/root\/project\/key.pem&#034;,<br \/>\n        ssl_verify&#061;False<br \/>\n    )<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    args &#061; _get_args()  # \u83b7\u53d6\u547d\u4ee4\u884c\u53c2\u6570<br \/>\n    if args.cpu_only:<br \/>\n        device_map &#061; &#034;cpu&#034;  # \u5982\u679c\u6307\u5b9a\u4e86\u4ec5\u4f7f\u7528CPU&#xff0c;\u8bbe\u7f6e\u8bbe\u5907\u6620\u5c04\u4e3aCPU<br \/>\n    else:<br \/>\n        device_map &#061; &#034;auto&#034;  # \u5426\u5219\u81ea\u52a8\u9009\u62e9\u8bbe\u5907<\/p>\n<p>    # \u52a0\u8f7d\u6a21\u578b<br \/>\n    model &#061; Qwen2AudioForConditionalGeneration.from_pretrained(<br \/>\n        args.checkpoint_path,<br \/>\n        torch_dtype&#061;&#034;auto&#034;,  # \u81ea\u52a8\u9009\u62e9\u6570\u636e\u7c7b\u578b<br \/>\n        device_map&#061;device_map,  # \u8bbe\u7f6e\u8bbe\u5907\u6620\u5c04<br \/>\n        resume_download&#061;True,  # \u65ad\u70b9\u7eed\u4f20<br \/>\n    ).eval()<br \/>\n    model.generation_config.max_new_tokens &#061; 2048  # \u8bbe\u7f6e\u6700\u5927\u751f\u6210token\u6570&#xff0c;\u7528\u4e8e\u957f\u5bf9\u8bdd<br \/>\n    print(&#034;generation_config&#034;, model.generation_config)<br \/>\n    processor &#061; AutoProcessor.from_pretrained(args.checkpoint_path, resume_download&#061;True)  # \u52a0\u8f7d\u5904\u7406\u5668<br \/>\n    _launch_demo(args)  # \u542f\u52a8\u6f14\u793a\u754c\u9762<\/p>\n<ul>\n<li>\u8fd0\u884c\u4e0a\u9762\u4ee3\u7801\u4e4b\u524d\u5148\u52304.1\u914d\u7f6essl<\/li>\n<\/ul>\n<h2>\u56db\u3001\u6210\u529f\u5b9e\u73b0\u8bed\u97f3\u4ea4\u4e92<\/h2>\n<p><img decoding=\"async\" src=\"2025-04-18vhvrissia1p.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h5>4.1 \u627e\u4e0d\u5230\u5f55\u97f3\u673a\u95ee\u9898<\/h5>\n<ul>\n<li>\u521b\u5efassl<\/li>\n<\/ul>\n<p>openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -nodes<\/p>\n<p>\u4e00\u76f4\u6309enter\u952e\u9ed8\u8ba4\u9009\u62e9\u5373\u53ef<\/p>\n<ul>\n<li>\u4fee\u6539launch<\/li>\n<\/ul>\n<p>vim demo\/web_demo_audio.py<\/p>\n<p>\u52a0\u5165ssl\u53c2\u6570&#xff0c;\u6ce8\u610f\u66ff\u6362\u8def\u5f84<\/p>\n<p>demo.queue().launch(<br \/>\n        share&#061;False,  # \u4e0d\u5171\u4eabURL<br \/>\n        inbrowser&#061;args.inbrowser,  # \u662f\u5426\u81ea\u52a8\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00<br \/>\n        server_port&#061;args.server_port,  # \u6307\u5b9a\u670d\u52a1\u5668\u7aef\u53e3<br \/>\n        server_name&#061;args.server_name,  # \u6307\u5b9a\u670d\u52a1\u5668\u540d\u79f0<br \/>\n        ssl_certfile&#061;&#034;\/root\/project\/cert.pem&#034;,<br \/>\n        ssl_keyfile&#061;&#034;\/root\/project\/key.pem&#034;,<br \/>\n        ssl_verify&#061;False<br \/>\n    )<\/p>\n<p><img decoding=\"async\" src=\"2025-04-18bagwdgnzocq.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801\u542f\u52a8<\/li>\n<\/ul>\n<p>python demo\/web_demo_audio.py<\/p>\n<ul>\n<li>\u6ce8\u610f\u7528https\u8bbf\u95ee<\/li>\n<\/ul>\n<p>https:\/\/\u670d\u52a1\u5668ip:\u7aef\u53e3<\/p>\n<p>\u62a5\u9519\u5408\u96c6&#xff1a; &#061;&#061;1. &#061;&#061; raise PydanticSchemaGenerationError( pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for &lt;class \u2018starlette.requests.Request\u2019&gt;. Set arbitrary_types_allowed&#061;True in the model_config to ignore this error or implement __get_pydantic_core_schema__ on your type to fully support it. If you got this error by calling handler() within __get_pydantic_core_schema__ then you likely need to call handler.generate_schema(&lt;some type&gt;) since we do not call __get_pydantic_core_schema__ on &lt;some type&gt; otherwise to avoid infinite recursion.<\/p>\n<p>For further information visit https:\/\/errors.pydantic.dev\/2.9\/u\/schema-for-unknown-type<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a Pydantic \u76f8\u5173\u7684\u9519\u8bef&#xff0c;\u4e3b\u8981\u662f\u56e0\u4e3a FastAPI \u548c Gradio \u7684\u7248\u672c\u517c\u5bb9\u6027\u95ee\u9898\u3002\u5177\u4f53\u539f\u56e0\u662f Starlette Request \u5bf9\u8c61\u65e0\u6cd5\u88ab Pydantic \u6b63\u786e\u5e8f\u5217\u5316\u3002\u95ee\u9898\u4e3b\u8981\u51fa\u5728 Gradio \u548c Pydantic \u7684\u7248\u672c\u517c\u5bb9\u6027\u4e0a<\/p>\n<p>\u7b2c\u4e00- \u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u914d\u7f6e\u7c7b&#xff1a;<\/p>\n<p>import gradio as gr<br \/>\nimport modelscope_studio as mgr<br \/>\nimport librosa<br \/>\nfrom transformers import AutoProcessor, Qwen2AudioForConditionalGeneration<br \/>\nfrom argparse import ArgumentParser<br \/>\nfrom pydantic import BaseModel<\/p>\n<p># \u6dfb\u52a0\u8fd9\u4e2a\u914d\u7f6e\u7c7b<br \/>\nclass ModelConfig(BaseModel):<br \/>\n    class Config:<br \/>\n        arbitrary_types_allowed &#061; True<\/p>\n<p># \u5728 _launch_demo \u51fd\u6570\u5f00\u59cb\u5904\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801<br \/>\ndef _launch_demo(args):<br \/>\n    gr.Config &#061; ModelConfig  # \u8bbe\u7f6e Gradio \u4f7f\u7528\u8fd9\u4e2a\u914d\u7f6e<br \/>\n    with gr.Blocks() as demo:<br \/>\n        # \u5176\u4f59\u4ee3\u7801\u4fdd\u6301\u4e0d\u53d8<\/p>\n<p>\u7b2c\u4e8c\u5347\u7ea7 Gradio \u7248\u672c<\/p>\n<p>pip install &#8211;upgrade gradio&#061;&#061;4.44.1<\/p>\n<p>2. freqs &#061; (inv_freq_expanded.float() &#064; position_ids_expanded.float()).transpose(1, 2) RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat2 in method wrapper_CUDA_bmm)<\/p>\n<p>\u4ece\u9519\u8bef\u65e5\u5fd7\u6765\u770b&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u8bbe\u5907\u4e0d\u5339\u914d\u7684\u95ee\u9898\u3002\u9519\u8bef\u53d1\u751f\u5728\u8fd0\u884c Qwen2-Audio \u6a21\u578b\u65f6&#xff0c;\u5177\u4f53\u9519\u8bef\u4fe1\u606f\u6307\u51fa\u5f20\u91cf\u5b58\u5728\u4e8e\u4e0d\u540c\u8bbe\u5907(CUDA:0 \u548c CPU)\u4e0a\u3002<\/p>\n<p>\u9700\u8981\u4fee\u6539\u7684\u662f predict \u51fd\u6570\u4e2d\u7684\u8bbe\u5907\u5904\u7406\u903b\u8f91 \u4e3b\u8981\u4fee\u6539\u5185\u5bb9&#xff1a; \u83b7\u53d6\u6a21\u578b\u5f53\u524d\u6240\u5728\u7684\u8bbe\u5907 \u5c06\u6240\u6709\u8f93\u5165\u5f20\u91cf\u79fb\u5230\u540c\u4e00\u8bbe\u5907\u4e0a \u4f7f\u7528\u66f4\u5b89\u5168\u7684\u8bbe\u5907\u8f6c\u79fb\u65b9\u5f0f<\/p>\n<p>def predict(chatbot, task_history):<br \/>\n    &#034;&#034;&#034;Generate a response from the model.&#034;&#034;&#034;<br \/>\n    print(f&#034;{task_history&#061;}&#034;)<br \/>\n    print(f&#034;{chatbot&#061;}&#034;)<br \/>\n    text &#061; processor.apply_chat_template(task_history, add_generation_prompt&#061;True, tokenize&#061;False)<br \/>\n    audios &#061; []<br \/>\n    for message in task_history:<br \/>\n        if isinstance(message[&#034;content&#034;], list):<br \/>\n            for ele in message[&#034;content&#034;]:<br \/>\n                if ele[&#034;type&#034;] &#061;&#061; &#034;audio&#034;:<br \/>\n                    audios.append(<br \/>\n                        librosa.load(ele[&#039;audio_url&#039;], sr&#061;processor.feature_extractor.sampling_rate)[0]<br \/>\n                    )<\/p>\n<p>    if len(audios)&#061;&#061;0:<br \/>\n        audios&#061;None<br \/>\n    print(f&#034;{text&#061;}&#034;)<br \/>\n    print(f&#034;{audios&#061;}&#034;)<\/p>\n<p>    # \u83b7\u53d6\u6a21\u578b\u6240\u5728\u8bbe\u5907<br \/>\n    device &#061; next(model.parameters()).device<\/p>\n<p>    # \u5904\u7406\u8f93\u5165\u6570\u636e<br \/>\n    inputs &#061; processor(text&#061;text, audios&#061;audios, return_tensors&#061;&#034;pt&#034;, padding&#061;True)<\/p>\n<p>    # \u5c06\u6240\u6709\u5f20\u91cf\u79fb\u5230\u6b63\u786e\u7684\u8bbe\u5907\u4e0a<br \/>\n    inputs &#061; {k: v.to(device) if hasattr(v, &#039;to&#039;) else v for k, v in inputs.items()}<\/p>\n<p>    generate_ids &#061; model.generate(**inputs, max_length&#061;256)<br \/>\n    generate_ids &#061; generate_ids[:, inputs[&#039;input_ids&#039;].size(1):]<\/p>\n<p>    response &#061; processor.batch_decode(generate_ids, skip_special_tokens&#061;True, clean_up_tokenization_spaces&#061;False)[0]<br \/>\n    print(f&#034;{response&#061;}&#034;)<br \/>\n    task_history.append({&#039;role&#039;: &#039;assistant&#039;,<br \/>\n                         &#039;content&#039;: response})<br \/>\n    chatbot.append((None, response))<br \/>\n    return chatbot, task_history<\/p>\n<p>\u53e6\u5916&#xff0c;\u5728\u4e3b\u7a0b\u5e8f\u90e8\u5206\u4e5f\u5efa\u8bae\u505a\u4ee5\u4e0b\u4fee\u6539&#xff1a;<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    args &#061; _get_args()<br \/>\n    if args.cpu_only:<br \/>\n        device_map &#061; &#034;cpu&#034;<br \/>\n    else:<br \/>\n        device_map &#061; &#034;auto&#034;<\/p>\n<p>    # \u8bbe\u7f6e\u9ed8\u8ba4\u8bbe\u5907<br \/>\n    import torch<br \/>\n    device &#061; torch.device(&#034;cuda&#034; if torch.cuda.is_available() and not args.cpu_only else &#034;cpu&#034;)<\/p>\n<p>    # \u52a0\u8f7d\u6a21\u578b<br \/>\n    model &#061; Qwen2AudioForConditionalGeneration.from_pretrained(<br \/>\n        args.checkpoint_path,<br \/>\n        torch_dtype&#061;torch.float16 if device.type &#061;&#061; &#034;cuda&#034; else torch.float32,  # \u6839\u636e\u8bbe\u5907\u9009\u62e9\u6570\u636e\u7c7b\u578b<br \/>\n        device_map&#061;device_map,<br \/>\n        resume_download&#061;True,<br \/>\n    ).eval()<\/p>\n<p>    print(f&#034;Model device: {next(model.parameters()).device}&#034;)<br \/>\n    model.generation_config.max_new_tokens &#061; 2048<br \/>\n    print(&#034;generation_config&#034;, model.generation_config)<\/p>\n<p>    processor &#061; AutoProcessor.from_pretrained(args.checkpoint_path, resume_download&#061;True)<br \/>\n    _launch_demo(args)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.7k\u6b21\uff0c\u70b9\u8d5e29\u6b21\uff0c\u6536\u85cf39\u6b21\u3002\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280_qwen2-audio<\/p>\n","protected":false},"author":2,"featured_media":14598,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[66,81,43],"topic":[],"class_list":["post-14618","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ai","tag-python","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/14618.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.7k\u6b21\uff0c\u70b9\u8d5e29\u6b21\uff0c\u6536\u85cf39\u6b21\u3002\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280_qwen2-audio\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/14618.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T13:18:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-6802512731b91.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/14618.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/14618.html\",\"name\":\"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T13:18:34+00:00\",\"dateModified\":\"2025-04-18T13:18:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/14618.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/14618.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/14618.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/14618.html","og_locale":"zh_CN","og_type":"article","og_title":"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.7k\u6b21\uff0c\u70b9\u8d5e29\u6b21\uff0c\u6536\u85cf39\u6b21\u3002\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280_qwen2-audio","og_url":"https:\/\/www.wsisp.com\/helps\/14618.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T13:18:34+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418131831-6802512731b91.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/14618.html","url":"https:\/\/www.wsisp.com\/helps\/14618.html","name":"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T13:18:34+00:00","dateModified":"2025-04-18T13:18:34+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/14618.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/14618.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/14618.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u963f\u91cc\u58f0\u97f3\u9879\u76eeQwen2-Audio\u7684\u90e8\u7f72\u5b89\u88c5\uff0c\u5728\u670d\u52a1\u5668Ubuntu22.04\u7cfb\u7edf\u2014\u2014\u70b9\u52a8\u79d1\u6280"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/14618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=14618"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/14618\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/14598"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=14618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=14618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=14618"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=14618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}