一、参考资料
免费又方便 - 魔改 Gradio 实现非 Gradio 程序的内网穿透
免费又方便 - 魔改 Gradio 实现非 Gradio 程序的内网穿透
二、frp相关介绍
1. frp工具
frpc代码仓库:https://github.com/fatedier/frp
frp是一个非常有名的内网穿透工具,其基本原理是:通过一个公网服务器,将本地的端口映射到公网服务器上,然后通过一个子域名访问该公网服务器,即可访问到本地服务。
2. frp架构
三、Gradio库
Gradio 代码仓库:https://github.com/gradio-app/gradio
Gradio 官网:https://www.gradio.app/
1. Gradio简介
Gradio是一个开源的Python库,旨在使用机器学习模型的演示和分享变得简单快捷。通过几行代码,开发者可以构建一个具有前端页面的交互式后端程序。目前很多在线体验大模型的项目都是基于gradio搭建而成的,比如stable diffusion的webui。
同时,Gradio提供内网穿透的功能,其通过设置 share=True
参数可创建一个内网穿透的子域名。Gradio的内网穿透功能是基于frp服务实现的。
2. 代码示例
import gradio as gr
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
demo.launch(share=True) # Share your demo with just 1 extra parameter 🚀
输出结果
(gradio) root@notebook-1823641624653922306-scnlbe5oi5-24558:/public/home/scnlbe5oi5/Downloads# python gradio_demo.py
Running on local URL: http://127.0.0.1:7860
Running on public URL: https://032a83c5773803845b.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)
四、gradio-tunneling库
1. 简介
gradio-tunneling 库是由up主 漆妮妮 基于Gradio库发布的内网穿透的库。
2. 安装 gradio-tunneling
# 安装 gradio-tunneling
pip install gradio-tunneling
3. 启动 label-studio 服务
以 label-studio 服务为例。
安装 label-studio:
pip install label-studio
启动 label-studio 服务:
label-studio
(gradio) root@notebook-1823641624653922306-scnlbe5oi5-24558:~# label-studio
=> Database and media directory: /root/.local/share/label-studio
=> Static URL is set to: /static/
=> Database and media directory: /root/.local/share/label-studio
=> Static URL is set to: /static/
/root/.local/share/label-studio/.env not found - if you're not configuring your environment separately, check this.
get 'SECRET_KEY' casted as '<class 'str'>' with default ''
September 04, 2024 - 03:39:02
Django version 3.2.25, using settings 'label_studio.core.settings.label_studio'
Starting development server at http://0.0.0.0:8080/
Quit the server with CONTROL-C.
4. 启用端口映射
gradio-tunneling -p 8080
(gradio) root@notebook-1823641624653922306-scnlbe5oi5-24558:/public/home/scnlbe5oi5/Downloads# gradio-tunneling -p 8080
公网访问地址:https://3aa8c5f845bd657bbe.gradio.live
这个共享链接将在 72 小时后过期,此程序将在 72 小时后关闭。