Skip to content

Experimental 📤

Gradio is an open-source library for quickly building interactive interfaces for machine learning models, scripts, or tools. It supports web-based displays, link sharing, and component drag-and-drop functionality, making it ideal for visualization, demonstrations, or validation.

Here, you can freely customize development and integration, flexibly adapt to your specific needs, and create personalized applications.

Application Preview

Plugin Development

1. Define Application

python
...
from src.app.prefs import INSTANCES as prefs
from src.gradio.tools import helper
from src.gradio.tools.toast import Toast

def gradio(**kwargs):

    # 配置
    cfg = prefs.get()

    # 界面
    with gr.Blocks(**kwargs) as app:

        with gr.Row():
            input_url = gr.Textbox(label=i18n("链接"), max_lines=1, placeholder=i18n("粘贴链接"))

        with gr.Row():
            title_txt = gr.Textbox(label=i18n("标题"), max_lines=1, interactive=False)

        with gr.Tabs() as tabs:
            with gr.TabItem(i18n("封面")):
                thumb_image = gr.Image(label=i18n("预览"), height=300)
            with gr.TabItem(i18n("视频")):
                video_table = gr.Dataframe(label=i18n("视频列表"), headers=[i18n("ID"), i18n("格式"), i18n("分辨率"), i18n("大小"), i18n("音频")], interactive=False, elem_id="output-table")
                video_fmt_input = gr.Textbox(label=i18n("ID"), max_lines=1, placeholder=i18n("请输入视频格式ID"))
                btn_v_download = gr.Button(i18n("下载"))
                video_file = gr.Video(label=i18n("预览"), height=300)
            with gr.TabItem(i18n("音频")):
                audio_table = gr.Dataframe(label=i18n("音频列表"), headers=[i18n("ID"), i18n("格式"), i18n("码率"), i18n("大小")], interactive=False, elem_id="output-table")
                audio_fmt_input = gr.Textbox(label=i18n("ID"), max_lines=1, placeholder=i18n("请输入音频格式ID"))
                btn_a_download = gr.Button(i18n("下载"))
                audio_file = gr.Audio(label=i18n("预览"), type="filepath")
            with gr.TabItem(i18n("字幕")):
                subs_table = gr.Dataframe(label=i18n("字幕列表"), headers=[i18n("语言"), i18n("格式"), i18n("URL")], interactive=False)
                sub_lang_input = gr.Textbox(label=i18n("语言"), max_lines=1, placeholder=i18n("请输入字幕语言代码"))
                sub_ext_input = gr.Textbox(label=i18n("格式"), max_lines=1, placeholder=i18n("请输入字幕格式"))
                btn_s_download = gr.Button(i18n("下载"))
                sub_file = gr.File(label=i18n("字幕文件"))

        with gr.Row():
            parse_btn = gr.Button(i18n("解析"), variant="primary")

        gr.Examples(
            label=i18n("示例"),
            examples=[
                ["bilibili", "https://www.bilibili.com/video/BV1BZ42187Qm"],
                ["youtube", "https://www.youtube.com/watch?v=SMWdVHNByhk"],
            ],
            inputs=[title_txt, input_url],
        )

        # 解析
        @gr.on(parse_btn.click, inputs=input_url, outputs=[thumb_image, title_txt, video_table, audio_table, subs_table])
        @metric
        def on_parse(url):
            try:
                if not url:
                    raise Toast.warn(i18n("请输入链接"))
                Toast.info(i18n("请稍后"))
                thumb, title, v_formats, a_formats, subs = parse_video(url)
                return thumb, title, v_formats, a_formats, subs
            except Exception as e:
                return None, None, [], [], []

        # 切换标签页
        @gr.on(tabs.change, outputs=[video_fmt_input, audio_fmt_input], show_api=False)
        def on_tab_change(active_tab):
            return "", ""

        # 视频选择
        @gr.on(video_table.select, outputs=video_fmt_input, show_api=False)
        def on_video_select(evt: gr.SelectData):
            selected_row = evt.row_value
            return selected_row[0]

        # 视频下载
        @gr.on(btn_v_download.click, inputs=[input_url, video_fmt_input], outputs=video_file)
        def on_download_video(url, fmt_id):
            if not url:
                return Toast.warn(i18n("请输入链接"))
            if not fmt_id:
                return Toast.warn(i18n("请选择ID"))
            Toast.info(i18n("请稍后"))
            output_dir = os.path.join(cfg.dev.output_dir, DLP_DIR)
            cbfile.mk_folder(output_dir, is_clean=cfg.dev.debug)
            filepath = download_by_format(url, output_dir, fmt_id)
            return cbfile.move_to_temp(filepath) if filepath else None
        ...

    return app

if __name__ == "__main__":
    gradio().launch(server_port=8001)
python
import gradio as gr

# Theme
default_themes = [
    gr.themes.Base,
    gr.themes.Default,
    gr.themes.Soft,
    gr.themes.Monochrome,
    gr.themes.Glass,
    gr.themes.Origin,
    gr.themes.Citrus,
    gr.themes.Ocean,
]

###################### Theme Customization ######################
custom_theme = gr.themes.Ocean(
    text_size="sm",
)
###################### Theme Customization ######################

def _default_theme():
    return custom_theme

if __name__ == "__main__":
    # 1、run `python builder.py` to open the theme builder
    # 2、or see https://huggingface.co/spaces/gradio/theme_builder
    from gradio import themes as t
    t.builder()

2. Register Application

bash
curl -X 'POST' \
  'http://172.18.0.1:8000/plugins/upsert' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
        "name": "dlp",                                      # Name
        "description": "YouTube Downloader Plus (yt-dlp)",  # Description
        "module": "src.gradio.pages.dlp_",                  # Path
        "attr": "gradio",                                   # Method
        "path": "/dlp",                                     # Request
        "status": 1                                         # Status
    }'

3. Open Application

ThumbnailVideoAudioSubtitle
gradio_custom_dlp_imagegradio_app_dlpgradio_custom_dlp_audiogradio_custom_dlp_subtitle

Scenario Customization

1: Batch Processing

Batch Operations?

To be added

2: AI Integration

How to integrate third-party AI workflows

To be added

Exclusive Plugin

Design, develop, and integrate specialized plugins based on CreatorBox to extend existing software functionality.

If you need custom plugin development, please leave a message at Plugin Development & Integration.