diff --git a/js/gtUI.css b/js/gtUI.css index d6e4a23..9d2a0b3 100644 --- a/js/gtUI.css +++ b/js/gtUI.css @@ -9,3 +9,29 @@ width: 100%; overflow: auto; } + +.audio-container { + display: flex; + align-items: center; + justify-content: center; + margin-top: 20px; +} + +.play-pause-button { + background-color: #ff5722; + border: none; + border-radius: 50%; + color: white; + cursor: pointer; + font-size: 24px; + height: 50px; + width: 50px; +} + +.play-pause-button:focus { + outline: none; +} + +.button-icon { + font-size: 24px; +} diff --git a/js/gtUINodes.js b/js/gtUINodes.js index ee9a8fa..a0c632d 100644 --- a/js/gtUINodes.js +++ b/js/gtUINodes.js @@ -229,6 +229,15 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { chainCallback(nodeType.prototype, "onNodeCreated", function() { const pathWidget = this.widgets.find((w) => w.name === widgetName); const fileInput = document.createElement("input"); + document.body.append(fileInput); + let uploadWidget = this.addWidget("button", "choose " + type + " to upload", "image", () => { + //clear the active click event + app.canvas.node_widget = null + + fileInput.click(); + }); + uploadWidget.options.serialize = false; + chainCallback(this, "onRemoved", () => { fileInput?.remove(); }); @@ -291,6 +300,24 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { }, }); } else if (type == "audio") { + // Create an audio element if not already created + // let audioWidget = document.getElementById('audio-widget'); + // let audioWidget = document.createElement('audio'); + // audioWidget.controls = true; // Add play controls + // document.body.append(audioWidget); // Append the audio element to the body or a specific container + // let audioButton = this.addWidget("button", "Play Audio ▶️", "audio", () => { + // audioWidget.play(); + // }); + // document.body.append(audioWidget); + // if (!audioWidget) { + // audioWidget = document.createElement('audio'); + // audioWidget.id = 'audio-widget'; + // audioWidget.controls = true; // Add play controls + // document.body.append(audioWidget); // Append the audio element to the body or a specific container + // let audioButton = this.addWidget("button", "Play Audio ▶️", "audio", () => { + // audioWidget.play(); + // }); + // } Object.assign(fileInput, { type: "file", accept: "audio/mpeg,audio/wav,audio/x-wav,audio/ogg", @@ -302,25 +329,58 @@ function gtUIAddUploadWidget(nodeType, nodeData, widgetName, type="audio") { return; } const filename = fileInput.files[0].name; + const filetype = fileInput.files[0].type; pathWidget.options.values.push(filename); pathWidget.value = filename; if (pathWidget.callback) { pathWidget.callback(filename) } + // Create a URL for the audio file and set it as the source of the audio element + // const audioURL = URL.createObjectURL(filename); + // audioWidget.src = audioURL; } }, + }); + + this.onDragOver = function( e) { + if (e.dataTransfer && e.dataTransfer.items) { + const audio = [...e.dataTransfer.items].find((f) => f.kind === "file" && f.type.startsWith("audio/")); + // console.log("dragover: " + audio); + // console.log(audio); + return !!audio; + } + return false; + } + this.onDragDrop = function (e) { + let handled = false; + for (const file of e.dataTransfer.files) { + if (file.type.startsWith("audio/")) { + handled = true; + console.log(file); + uploadFile(file, !handled); + handled = true; + const filename = file.name; + pathWidget.options.values.push(filename); + pathWidget.value = filename; + if (pathWidget.callback) { + pathWidget.callback(filename) + } + + // Create a URL for the audio file and set it as the source of the audio element + // const audioURL = URL.createObjectURL(file); + // audioWidget.src = audioURL; + // audioWidget.play(); // Optionally play the audio automatically + + + } + } + return handled; + + } }else { throw "Unknown upload type" } - document.body.append(fileInput); - let uploadWidget = this.addWidget("button", "choose " + type + " to upload", "image", () => { - //clear the active click event - app.canvas.node_widget = null - - fileInput.click(); - }); - uploadWidget.options.serialize = false; }); } app.registerExtension({ @@ -335,40 +395,27 @@ app.registerExtension({ init() { - // console.log("Griptape UI Extension Loaded"); - // let logging_entries = app.logging.app.logging.entries; - // // Filter to find the entry with type "warn" - // let warn_entry = logging_entries.find(entry => entry.type === "warn"); - // if (warn_entry) { - // console.log("Warn Entry:"); - // console.log(warn_entry); - // } else { - // console.log("No warn entry found"); - // } - - // console.log(logging_entries); - // let graphData = app.graphData; - // for (let n of graphData.nodes) { - // // Find missing node types - // if (!(n.type in LiteGraph.registered_node_types)) { - // missingNodeTypes.push(n.type); - // n.type = sanitizeNodeName(n.type); - // } - // } }, async beforeRegisterNodeDef(nodeType, nodeData, app) { + // if (nodeData.category.startsWith("Griptape")) { + // const origOnConfigure = nodeType.prototype.onConfigure; + // nodeType.prototype.onConfigure = function () { + // this.bgcolor = "#171717"; + // this.color = getColor(nodeData.category); + // }; + // Set Config node randomization to Fixed - if (nodeData.name.includes("Config")) { + if (nodeData.name.includes("Griptape Agent Config")) { const onNodeCreated = nodeType.prototype.onNodeCreated; nodeType.prototype.onNodeCreated = async function () { for (const widget of this.widgets) { if (widget.name === "control_after_generate") { widget.value = "fixed"; } + } } - } } // Create Audio Node diff --git a/nodes/audio_nodes.py b/nodes/audio_nodes.py index 0eda757..35bfabf 100644 --- a/nodes/audio_nodes.py +++ b/nodes/audio_nodes.py @@ -1,8 +1,14 @@ +import mimetypes import os import folder_paths +def is_audio_file(filepath): + mime_type, _ = mimetypes.guess_type(filepath) + return mime_type is not None and mime_type.startswith("audio/") + + class gtUILoadAudio: DESCRIPTION = "Load an audio file for processing." @@ -13,6 +19,7 @@ class gtUILoadAudio: f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f)) + and is_audio_file(os.path.join(input_dir, f)) ] return { "required": {"audio": (sorted(files), {"audio_upload": True})}, diff --git a/nodes/base_loader.py b/nodes/base_loader.py new file mode 100644 index 0000000..bf987d3 --- /dev/null +++ b/nodes/base_loader.py @@ -0,0 +1,74 @@ +from griptape.structures import Agent +from griptape.tasks import PromptTask + + +class gtUIBaseTask: + def __init__(self): + pass + + DESCRIPTION = "Run a PromptTask." + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "STRING": ( + "STRING", + { + "multiline": True, + }, + ), + }, + "optional": { + "input_string": ( + "STRING", + { + "forceInput": True, + }, + ), + "agent": ("AGENT",), + }, + } + + RETURN_TYPES = ( + "STRING", + "AGENT", + ) + RETURN_NAMES = ( + "OUTPUT", + "AGENT", + ) + + FUNCTION = "run" + OUTPUT_NODE = True + + CATEGORY = "Griptape/Agent Tasks" + + def get_prompt_text(self, STRING, input_string): + # Get the prompt text + if not input_string: + prompt_text = STRING + else: + prompt_text = STRING + "\n\n" + input_string + + return prompt_text + + def run( + self, + STRING, + input_string=None, + agent=None, + ): + if not agent: + agent = Agent() + + prompt_text = self.get_prompt_text(STRING, input_string) + try: + agent.add_task(PromptTask(prompt_text)) + except Exception as e: + print(e) + result = agent.run() + return ( + result.output_task.output.value, + agent, + ) diff --git a/nodes/config_nodes.py b/nodes/config_nodes.py index 9ba395d..a6eabbd 100644 --- a/nodes/config_nodes.py +++ b/nodes/config_nodes.py @@ -154,7 +154,7 @@ class gtUIOllamaStructureConfig(gtUIBaseConfig): def create(self, prompt_model, temperature, seed): custom_config = StructureConfig( prompt_driver=OllamaPromptDriver( - model=prompt_model, temperature=temperature + model=prompt_model, options={"temperature": temperature} ), ) diff --git a/requirements.txt b/requirements.txt index 4656482..96c512c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -griptape [all] == 0.27.1 +griptape [all] == 0.27.2 python-dotenv duckduckgo_search