# modelscope/funclip architecture

> Architecture diagram of the GitHub repository modelscope/funclip, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/modelscope/funclip
- Repository: https://github.com/modelscope/funclip

## Overview

##### Project type and purpose
- FunClip is a Python‑based, locally deployed video clipping tool with both a GUI (Gradio web service) and a command‑line interface (CLI).
- It orchestrates speech recognition (ASR), optional large‑language‑model (LLM) inference, subtitle generation, and video processing to let users clip segments from input videos.

##### File structure
- Top level:
- launch.py (Gradio server entrypoint)
- videoclipper.py (CLI entrypoint with “stage” flags)
- requirements.txt, configs, fonts, docs, tests
- funclip/llm: adapters for various LLM APIs (OpenAI, Qwen, g4f) and demo prompts
- funclip/utils: helper modules (arg parsing, subtitle handling, translation, theme config)
- funclip/introduction.py: UI content injector
- funclip/launch.py: UI wiring (Gradio components → backend functions)
- funclip/videoclipper.py: two‑stage pipeline (stage 1 = ASR → generate SRT; stage 2 = clipping via ffmpeg/moviepy, ImageMagick)

##### Additional README insights
- Core flow:
1. User uploads video
2. FunASR Paraformer models perform ASR with timestamps (and optional speaker diarization)
3. Gradio UI displays transcript; user picks text spans or triggers LLM to generate timestamps
4. Video is clipped via ffmpeg / MoviePy; subtitle SRTs are generated
- CLI does the same in “recognize” and “clip” stages
- Optional dependencies: ffmpeg, ImageMagick, custom font

##### Key reminders
- Both interactive (Gradio) and batch (CLI) flows
- Fallback paths (user‑selected transcript vs. LLM‑generated timestamps)
- Detail intermediate artifacts (raw audio, JSON result, SRT, final MP4)
- Don’t over‑complicate—show each logical component once with its major interfaces

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        WebUI["Web UI (Gradio)"]:::internal
        CLI["CLI Client"]:::internal
        Intro["UI Content Injector\n(funclip/introduction.py)"]:::internal
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        WebOrch["Web Orchestrator\n(funclip/launch.py)"]:::internal
        CLIOrch["CLI Orchestrator\n(funclip/videoclipper.py)"]:::internal
        Utils["Utility Helpers"]:::internal
    end

    subgraph "Utils Modules"
        direction TB
        ArgParse["Argparse Tools\n(funclip/utils/argparse_tools.py)"]:::internal
        Trans["Translation Utils\n(funclip/utils/trans_utils.py)"]:::internal
        Theme["Theme Config\n(funclip/utils/theme.json)"]:::internal
    end

    %% Domain Services
    subgraph "Domain Services"
        direction TB
        ASR["ASR Engine\n(funclip/videoclipper.py)"]:::domain
        Subtitle["Subtitle Processor\n(funclip/utils/subtitle_utils.py)"]:::domain
        subgraph "LLM Inference Module"
            direction TB
            OpenAIAPI["openai_api.py"]:::domain
            QwenAPI["qwen_api.py"]:::domain
            G4fAPI["g4f_openai_api.py"]:::domain
            DemoPrompt["demo_prompt.py"]:::domain
        end
        VideoProc["Video Processor\n(funclip/videoclipper.py)"]:::domain
    end

    %% Data Layer
    FS["Local File System"]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        OpenAIExt["OpenAI API"]:::external
        QwenExt["Qwen API"]:::external
        Modelscope["Modelscope / HuggingFace"]:::external
    end

    %% Presentation to Application
    WebUI -->|"HTTP Request"| WebOrch
    CLI -->|"CLI Args"| CLIOrch
    Intro --> WebOrch

    %% Application to Utils
    WebOrch --> Utils
    CLIOrch --> Utils
    Utils --> ArgParse
    Utils --> Trans
    Utils --> Theme

    %% Orchestrator to Domain Services
    WebOrch -->|"extract audio"| ASR
    CLIOrch -->|"extract audio"| ASR
    ASR -->|"JSON transcript"| Subtitle
    Subtitle -->|"SRT file"| FS
    WebOrch -->|"transcript text"| OpenAIAPI
    WebOrch -->|"transcript text"| QwenAPI
    WebOrch -->|"transcript text"| G4fAPI
    WebOrch -->|"transcript text"| DemoPrompt
    OpenAIAPI -->|"timestamps"| WebOrch
    QwenAPI -->|"timestamps"| WebOrch
    G4fAPI -->|"timestamps"| WebOrch
    DemoPrompt -->|"timestamps"| WebOrch
    WebOrch -->|"video + timestamps"| VideoProc
    CLIOrch -->|"video + timestamps"| VideoProc
    VideoProc -->|"clipped video"| FS

    %% File System to Presentation
    FS -->|"serve files"| WebUI

    %% Orchestrator to External Services
    OpenAIAPI --> OpenAIExt
    QwenAPI --> QwenExt
    DemoPrompt --> Modelscope

    %% Click Events
    click WebUI "https://github.com/modelscope/funclip/blob/main/launch.py"
    click Intro "https://github.com/modelscope/funclip/blob/main/funclip/introduction.py"
    click WebOrch "https://github.com/modelscope/funclip/blob/main/funclip/launch.py"
    click CLI "https://github.com/modelscope/funclip/blob/main/videoclipper.py"
    click CLIOrch "https://github.com/modelscope/funclip/blob/main/funclip/videoclipper.py"
    click ASR "https://github.com/modelscope/funclip/blob/main/funclip/videoclipper.py"
    click Subtitle "https://github.com/modelscope/funclip/blob/main/funclip/utils/subtitle_utils.py"
    click OpenAIAPI "https://github.com/modelscope/funclip/blob/main/funclip/llm/openai_api.py"
    click QwenAPI "https://github.com/modelscope/funclip/blob/main/funclip/llm/qwen_api.py"
    click G4fAPI "https://github.com/modelscope/funclip/blob/main/funclip/llm/g4f_openai_api.py"
    click DemoPrompt "https://github.com/modelscope/funclip/blob/main/funclip/llm/demo_prompt.py"
    click VideoProc "https://github.com/modelscope/funclip/blob/main/funclip/videoclipper.py"
    click ArgParse "https://github.com/modelscope/funclip/blob/main/funclip/utils/argparse_tools.py"
    click Trans "https://github.com/modelscope/funclip/blob/main/funclip/utils/trans_utils.py"
    click Theme "https://github.com/modelscope/funclip/blob/main/funclip/utils/theme.json"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#21618C,color:#1B2631
    classDef domain fill:#A9DFBF,stroke:#196F3D,color:#1B2631
    classDef external fill:#F5B041,stroke:#B9770E,color:#1B2631
    classDef data fill:#D5D8DC,stroke:#85929E,color:#1B2631
```
