Metadata-Version: 2.4
Name: fabricatio-yue
Version: 0.3.2
Summary: An extension of fabricatio, provide capability to compose lyrics that can be used in music generation with YuE.
Project-URL: Homepage, https://github.com/Whth/fabricatio
Project-URL: Repository, https://github.com/Whth/fabricatio
Project-URL: Issues, https://github.com/Whth/fabricatio/issues
Author-email: Whth <zettainspector@foxmail.com>
License: MIT License
        
        Copyright (c) 2025 Whth Yotta
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Typing :: Typed
Requires-Python: <3.15,>=3.12
Requires-Dist: fabricatio-core
Requires-Dist: more-itertools>=10.7.0
Requires-Dist: orjson>=3.11.4
Requires-Dist: pydantic>=2.11.5
Provides-Extra: cli
Requires-Dist: questionary>=2.1.0; extra == 'cli'
Requires-Dist: typer>=0.15.2; extra == 'cli'
Description-Content-Type: text/markdown

# `fabricatio-yue`

[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
![Python Versions](https://img.shields.io/pypi/pyversions/fabricatio-yue)
[![PyPI Version](https://img.shields.io/pypi/v/fabricatio-yue)](https://pypi.org/project/fabricatio-yue/)
[![PyPI Downloads](https://static.pepy.tech/badge/fabricatio-yue/week)](https://pepy.tech/projects/fabricatio-yue)
[![PyPI Downloads](https://static.pepy.tech/badge/fabricatio-yue)](https://pepy.tech/projects/fabricatio-yue)

AI-powered lyrics composition for music generation with [YuE](https://github.com/multimodal-art-projection/YuE). Provides genre selection, structured lyric generation, and batch song composition integrated into the Fabricatio agent framework.

## Installation

```bash
pip install fabricatio[yue]
```

Or with the CLI extras:

```bash
pip install fabricatio[yue,cli]
```

## Overview

`fabricatio-yue` generates complete song lyrics with genre-appropriate structure (verse, chorus, bridge, etc.). It selects suitable genres from a taxonomy of 200+ tags across five categories — **genre**, **instrument**, **mood**, **gender**, **timbre** — and feeds them into LLM-driven lyric generation. Songs are saved as Markdown files with embedded metadata.

## Key Components

### Models

| Class | Description |
|-------|-------------|
| `Segment` | A song section with `section_type` (verse, chorus, bridge, intro, outro, etc.), `duration` in seconds, `lyrics` as lines, and optional `extra_genres`. `assemble` property formats it as `[section_type]\nlyrics`. |
| `Song` | A complete song with `name`, `description`, `genres`, and an ordered list of `Segment`s. Computes total `duration` from segments. `save_to(path)` writes it as a Markdown file. |

### Capabilities

| Class | Description |
|-------|-------------|
| `SelectGenre` | Selects genres from a category based on text requirements. `select_genre(req, classifier, genres)` picks matching genres; `gather_genres(req)` iterates all categories and returns the combined results. |
| `Lyricize` | Extends `Propose` and `SelectGenre`. `lyricize(requirement)` gathers genres, renders a prompt template, and returns a `Song` object. Accepts a single string or a list for batch generation. |

### Actions

| Class | Description |
|-------|-------------|
| `Compose` | Full pipeline action: `_execute(req, output)` calls `lyricize()` then `save_to(output)`. Usable in a `WorkFlow` step. |

### CLI

```bash
yuek compose -r "an upbeat pop song about summer" -o ./output
```

## Usage

```python
from fabricatio_core import Event, Role, Task, WorkFlow
from fabricatio_yue.actions.compose import Compose

ns = "compose"
Role.with_bio().subscribe(
    Event.quick_instantiate(ns),
    WorkFlow(steps=(Compose().to_task_output(),))
).dispatch()

Task(name="compose song").update_init_context(
    req="a melancholic jazz ballad",
    output="./songs",
).delegate_blocking(ns)
```

Using the `Lyricize` capability directly:

```python
from fabricatio_yue.capabilities.lyricize import Lyricize

lyricizer = Lyricize()
song = await lyricizer.lyricize("a fast punk anthem about resilience")
print(song.model_dump_json(indent=2))
```

Using `SelectGenre`:

```python
from fabricatio_yue.capabilities.genre import SelectGenre

selector = SelectGenre()
genres = await selector.gather_genres("dark atmospheric electronic")
```

Song and Segment model usage:

```python
from fabricatio_yue.models.segment import Segment, Song

segments = [
    Segment(section_type="verse", duration=30, lyrics=["First verse line 1", "First verse line 2"]),
    Segment(section_type="chorus", duration=20, lyrics=["Chorus line 1", "Chorus line 2"]),
]

song = Song(
    name="my_song",
    description="A generated song",
    genres=["electronic", "ambient"],
    segments=segments,
)

song.save_to("./songs")
print(song.duration)  # 50
```

## Dependencies

- `fabricatio-core` — core agent framework
- `more-itertools` — flatten genre results
- `orjson` — fast JSON loading of genre tags
- `pydantic` — data model validation

Optional CLI extras: `questionary`, `typer`.

## Configuration

Settings are loaded via `fabricatio_yue.config.yue_config` (an instance of `YueConfig`). Key options:

- `segment_types` — list of valid section types (default: `["verse", "chorus", "bridge", "intro", "outro", "solo", "beat", "end"]`)
- `genre` — dict mapping category to list of genres, loaded from `top_200_tags.json`
- `lyricize_template`, `select_genre_template`, `song_save_template` — template names for LLM prompts

## License

MIT — see [LICENSE](../../LICENSE)
