简单使用Gradio以实现内网穿透

一、参考资料

免费又方便 - 魔改 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 小时后关闭。

5. 访问服务

在这里插入图片描述

五、FAQ

Q. Could not create share link. Missing file:/PATH/TO/gradio/frpc_linux_amd64_v0.2

解决方法,请参考:快速体验LLaMA-Factory 私有化部署和高效微调Llama3模型FAQ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花花少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值