云计算百科
云计算领域专业知识百科平台

[详细教程] 服务器上用gradio无法远程访问

情况描述:在服务器部署的ChatGLM3-6B,使用ChatGLM3/basic_demo/web_demo_gradio.py启动频频出错。首先介绍通用的gradio远程访问遇到报错的解决方法,后面为同样在部署ChatGLM3的你介绍需要解决的软件版本依赖。

报错内容:

To create a public link, set `share=True` in `launch()`.

解决:对正在执行的.py文件进行修改,在demo.launch函数中设置share=True

demo.launch(server_name=socket.gethostbyname(socket.gethostname()), server_port=7870, inbrowser=True, share=True)

报错内容:

Could not create share link. Missing file: /root/miniconda3/envs/myenv/lib/python3.10/site-packages/gradio/frpc_linux_amd64_v0.3. 

Please check your internet connection. This can happen if your antivirus software blocks the download of this file. You can install manually by following these steps: 

1. Download this file: https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64 2. Rename the downloaded file to: frpc_linux_amd64_v0.3 3. Move the file to this location: /root/miniconda3/envs/myenv/lib/python3.10/site-packages/gradio

解决:按照上面的三条照做就行

报错内容:

Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.

解决:为刚刚放进去的文件添加执行权限

chmod +x /root/miniconda3/envs/myenv/lib/python3.10/site-packages/gradio/frpc_linux_amd64_v0.3

报错内容:

2025/02/16 19:18:28 [W] [service.go:132] login to server failed: EOF

Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.

解决:对正在执行的.py文件进行修改,在demo.launch函数中设置server_name='0.0.0.0'

demo.launch(server_name='0.0.0.0', server_port=7870, inbrowser=True, share=True)

原因:服务器上部署的gradio能够远程访问需要①服务器连接到Gradio官网②Gradio官网生成一个公共访问的URL,让其它电脑能够访问到服务器发出的内容。

因此如果server_name='127.0.0.1',那么服务器发出的数据只能被服务器访问,原因如下:

【计算机网络】localhost,127.0.0.1 和 0.0.0.0傻傻分不清?这篇文章带你认识_localhost:127.0.0.1 ,0.0.0.0-CSDN博客

同时要确认Gradio官网稳定运行,其官网链接:https://status.gradio.app

解决完这些就可以

①复制服务器SSH登录的登录指令和密码,并替换到相应位置

②查看demo.launch()函数中的server_port=7870,并替换到相应位置

例:登录指令:ssh -p 12345 root@connect.nmb1.seetacloud.com

ssh -CNg -L6006:127.0.0.1:7870 root@connect.nmb1.seetacloud.com -p 12345

③然后把替换好的指令用在cmd,之后手动输入刚刚复制下来的密码就可以

④浏览器访问http://127.0.0.1:6006


如果你是在部署ChatGLM3-6B时遇到了和我描述中一样的问题,可以参考我解决依赖包的方法:

时间:2025.2.16

遇到报错1:

ModuleNotFoundError: No module named 'peft'

解决:

pip install peft 

遇到报错2:

ImportError: cannot import name 'EncoderDecoderCache' from 'transformers' (/root/miniconda3/envs/myenv/lib/python3.10/site-packages/transformers/__init__.py)

解决:

pip install –upgrade transformers  #我下载到的是4.48.3

赞(0)
未经允许不得转载:网硕互联帮助中心 » [详细教程] 服务器上用gradio无法远程访问
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!