From 5169285be01b5555a3b13c6f8f18849b96faf627 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 5 Jun 2024 13:13:57 -0400 Subject: [PATCH] Add comfy-ui command --- emacs/.emacs.d/config/init-ai.el | 50 +++++++++++++++++++++++++++++++ emacs/.emacs.d/config/init-llm.el | 11 ------- emacs/.emacs.d/init.el | 2 +- 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 emacs/.emacs.d/config/init-ai.el delete mode 100644 emacs/.emacs.d/config/init-llm.el diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el new file mode 100644 index 0000000..9fd876b --- /dev/null +++ b/emacs/.emacs.d/config/init-ai.el @@ -0,0 +1,50 @@ +;; -*- lexical-binding: t; -*- + +(use-package llama + :straight `(:local-repo ,(expand-file-name "packages/llama" user-emacs-directory) :type nil) + :load-path "packages/llama" + :config + (require 'llm-ollama) + (setq llama-llm-provider (make-llm-ollama :chat-model "llama3:latest") + llm-warn-on-nonfree nil)) + +(defvar comfy-ui-path (expand-file-name "~/ComfyUI") + "Path to ComfyUI source repository.") + +(defvar comfy-ui-command (list "pipenv" "run" "python" "main.py") + "Command to run ComfyUI server.") + +(defvar-local comfy-ui--url nil + "URL for this buffer's ComfyUI process.") + +(defun comfy-ui-process-filter (proc string) + (when-let ((match (s-match "To see the GUI go to: \\(.*\\)" string))) + (with-current-buffer (process-buffer proc) + (setq comfy-ui--url (nth 1 match)) + (browse-url comfy-ui--url))) + (when (buffer-live-p (process-buffer proc)) + (with-current-buffer (process-buffer proc) + (let ((moving (= (point) (process-mark proc)))) + (save-excursion + ;; Insert the text, advancing the process marker. + (goto-char (process-mark proc)) + (insert string) + (set-marker (process-mark proc) (point))) + (if moving (goto-char (process-mark proc))))))) + +(defun comfy-ui () + "Launch Comfy UI in a subprocess and opens the web UI." + (interactive) + (unless (file-exists-p (expand-file-name (f-join comfy-ui-path "main.py"))) + (user-error "Could not find ComfyUI installation!")) + (if-let ((proc (get-process "comfy-ui"))) + (with-current-buffer (process-buffer proc) + (browse-url comfy-ui--url)) + (with-temp-buffer + (cd comfy-ui-path) + (make-process :name "comfy-ui" + :buffer "*ComfyUI*" + :command comfy-ui-command + :filter #'comfy-ui-process-filter)))) + +(provide 'init-ai) diff --git a/emacs/.emacs.d/config/init-llm.el b/emacs/.emacs.d/config/init-llm.el deleted file mode 100644 index 4c81823..0000000 --- a/emacs/.emacs.d/config/init-llm.el +++ /dev/null @@ -1,11 +0,0 @@ -;; -*- lexical-binding: t; -*- - -(use-package llama - :straight `(:local-repo ,(expand-file-name "packages/llama" user-emacs-directory) :type nil) - :load-path "packages/llama" - :config - (require 'llm-ollama) - (setq llama-llm-provider (make-llm-ollama :chat-model "llama3:latest") - llm-warn-on-nonfree nil)) - -(provide 'init-llm) diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index 23ba4e7..7a31a15 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -131,7 +131,7 @@ (require 'init-games) (require 'handwriting) (require 'init-navi) -(require 'init-llm) +(require 'init-ai) (when (string-equal system-type "darwin") (require 'init-mac))