Class: PodcastBuddy::SystemDependency
- Inherits:
-
Struct
- Object
- Struct
- PodcastBuddy::SystemDependency
- Defined in:
- lib/podcast_buddy/system_dependency.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .auto_install!(name) ⇒ Object
- .download_model(model) ⇒ Object
- .model_downloaded?(model) ⇒ Boolean
- .resolve_whisper_model(model) ⇒ Object
Instance Method Summary collapse
-
#initialize(name:, type: :system) ⇒ SystemDependency
constructor
A new instance of SystemDependency.
- #install ⇒ Object
- #installed? ⇒ Boolean
Constructor Details
#initialize(name:, type: :system) ⇒ SystemDependency
Returns a new instance of SystemDependency.
8 9 10 11 |
# File 'lib/podcast_buddy/system_dependency.rb', line 8 def initialize(name:, type: :system) @name = name @type = type || :system end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/podcast_buddy/system_dependency.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type
4 5 6 |
# File 'lib/podcast_buddy/system_dependency.rb', line 4 def type @type end |
Class Method Details
.auto_install!(name) ⇒ Object
13 14 15 16 |
# File 'lib/podcast_buddy/system_dependency.rb', line 13 def self.auto_install!(name) system_dependency = new(name: name, type: :system) system_dependency.install unless system_dependency.installed? end |
.download_model(model) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/podcast_buddy/system_dependency.rb', line 27 def self.download_model(model) originating_directory = Dir.pwd Dir.chdir("whisper.cpp") PodcastBuddy.logger.info "Downloading GGML model: #{PodcastBuddy.whisper_model}" PodcastBuddy.logger.info `bash ./models/download-ggml-model.sh #{PodcastBuddy.whisper_model}` ensure Dir.chdir(originating_directory) end |
.model_downloaded?(model) ⇒ Boolean
23 24 25 |
# File 'lib/podcast_buddy/system_dependency.rb', line 23 def self.model_downloaded?(model) File.exist?(File.join(PodcastBuddy.root, "whisper.cpp", "models", "ggml-#{model}.bin")) end |
.resolve_whisper_model(model) ⇒ Object
18 19 20 21 |
# File 'lib/podcast_buddy/system_dependency.rb', line 18 def self.resolve_whisper_model(model) return if model_downloaded?(model) download_model(model) end |
Instance Method Details
#install ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/podcast_buddy/system_dependency.rb', line 45 def install PodcastBuddy.logger.info "Installing #{name}..." originating_directory = Dir.pwd if name.to_s == "whisper" Dir.chdir(PodcastBuddy.root) PodcastBuddy.logger.info `git clone https://github.com/ggerganov/whisper.cpp` Dir.chdir("whisper.cpp") PodcastBuddy.logger.info "Downloading GGML model: #{PodcastBuddy.whisper_model}" PodcastBuddy.logger.info `bash ./models/download-ggml-model.sh #{PodcastBuddy.whisper_model}` PodcastBuddy.logger.info `make && make stream` else `brew list #{name} || brew install #{name}` end ensure Dir.chdir(originating_directory) end |
#installed? ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/podcast_buddy/system_dependency.rb', line 36 def installed? PodcastBuddy.logger.info "Checking for system dependency: #{name}..." if name.to_s == "whisper" Dir.exist?("whisper.cpp") else system("brew list -1 #{name} > /dev/null") || system("type -a #{name}") end end |