diff --git a/app.py b/app.py index 20422f0..1ab6802 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,10 @@ from plugin import AudioLDMPlugin from tuneflow_devkit import Runner from pathlib import Path +import uvicorn app = Runner(plugin_class_list=[AudioLDMPlugin], bundle_file_path=str( Path(__file__).parent.joinpath('bundle.json').absolute())).start(path_prefix='/plugins/audio-ldm') + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/bundle.json b/bundle.json index 4952074..0c16049 100644 --- a/bundle.json +++ b/bundle.json @@ -1,28 +1,36 @@ { - "plugins": [ - { - "providerId": "andantei", - "providerDisplayName": { - "zh": "Andantei行板", - "en": "Andantei" - }, - "pluginId": "audioldm-generate", - "pluginDisplayName": { - "zh": "[AI] 文字生成音频 (AudioLDM)", - "en": "[AI] Text-to-Audio (AudioLDM)" - }, - "pluginDescription": { - "zh": "用一段提示词生成音频或音乐", - "en": "Generate audio or music from a short prompt text" - }, - "version": "1.0.0", - "supportedPlatforms": ["desktop"], - "isInDevelopment": true, - "minRequiredDesktopVersion": "1.8.9", - "options": { - "allowReset": true, - "allowManualApplyAdjust": true + "plugins": [ + { + "providerId": "andantei", + "providerDisplayName": { + "zh": "Andantei行板", + "en": "Andantei" + }, + "pluginId": "audioldm-generate", + "pluginDisplayName": { + "zh": "[AI] 文字生成音频 (AudioLDM)", + "en": "[AI] Text-to-Audio (AudioLDM)" + }, + "pluginDescription": { + "zh": "用一段提示词生成音频或音乐", + "en": "Generate audio or music from a short prompt text" + }, + "version": "1.0.0", + "supportedPlatforms": ["desktop"], + "minRequiredDesktopVersion": "1.8.9", + "options": { + "allowReset": true, + "allowManualApplyAdjust": true + }, + "triggers": [ + { + "type": "context-track-content", + "config": { + "allowedTrackTypes": ["audio"] + } } - } - ] -} \ No newline at end of file + ], + "categories": ["generate"] + } + ] +} diff --git a/plugin.py b/plugin.py index 1cd6091..28ca91e 100644 --- a/plugin.py +++ b/plugin.py @@ -1,4 +1,4 @@ -from tuneflow_py import TuneflowPlugin, ParamDescriptor, Song, TrackType, WidgetType, InjectSource +from tuneflow_py import TuneflowPlugin, ParamDescriptor, Song, WidgetType, InjectSource, TuneflowPluginTriggerData from typing import Dict, Any from audioldm import text_to_audio, build_model from pathlib import Path @@ -110,6 +110,11 @@ def params(song: Song) -> Dict[str, ParamDescriptor]: @staticmethod def run(song: Song, params: Dict[str, Any]): + trigger: TuneflowPluginTriggerData = params["trigger"] + track_id =trigger["entities"][0]["trackId"] + track = song.get_track_by_id(track_id=track_id) + if track is None: + raise Exception('track not found') model_path = str(Path(__file__).parent.joinpath('ckpt/ldm_trimmed.ckpt').absolute()) model = build_model(ckpt_path=model_path) # TODO: Support prompt i18n @@ -123,7 +128,6 @@ def run(song: Song, params: Dict[str, Any]): for file_bytes in file_bytes_list: try: file_bytes.seek(0) - track = song.create_track(type=TrackType.AUDIO_TRACK) track.create_audio_clip(clip_start_tick=0, audio_clip_data={ "audio_data": { "format": "wav", @@ -132,6 +136,7 @@ def run(song: Song, params: Dict[str, Any]): "duration": params["duration"], "start_tick": params["playhead_tick"] }) + break except: print(traceback.format_exc()) diff --git a/requirements.txt b/requirements.txt index 19ab0ad..86908ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,4 @@ pandas torchlibrosa==0.0.9 transformers ftfy -tuneflow-py>=0.3.0 \ No newline at end of file +tuneflow-py>=0.3.6 \ No newline at end of file