Class: RubyLlmAgents::BackgroundRemoverGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- RubyLlmAgents::BackgroundRemoverGenerator
- Defined in:
- lib/generators/ruby_llm_agents/background_remover_generator.rb
Overview
BackgroundRemover generator for creating new background removers
Usage:
rails generate ruby_llm_agents:background_remover Product
rails generate ruby_llm_agents:background_remover Portrait --model segment-anything --alpha_matting
rails generate ruby_llm_agents:background_remover Photo --refine_edges --return_mask
This will create:
- app/agents/images/product_background_remover.rb
Instance Method Summary collapse
- #create_background_remover_file ⇒ Object
- #ensure_base_class_and_skill_file ⇒ Object
- #show_usage ⇒ Object
Instance Method Details
#create_background_remover_file ⇒ Object
51 52 53 54 |
# File 'lib/generators/ruby_llm_agents/background_remover_generator.rb', line 51 def create_background_remover_file remover_path = name.underscore template "background_remover.rb.tt", "app/agents/images/#{remover_path}_background_remover.rb" end |
#ensure_base_class_and_skill_file ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/ruby_llm_agents/background_remover_generator.rb', line 32 def ensure_base_class_and_skill_file images_dir = "app/agents/images" # Create directory if needed empty_directory images_dir # Create base class if it doesn't exist base_class_path = "#{images_dir}/application_background_remover.rb" unless File.exist?(File.join(destination_root, base_class_path)) template "application_background_remover.rb.tt", base_class_path end # Create skill file if it doesn't exist skill_file_path = "#{images_dir}/BACKGROUND_REMOVERS.md" unless File.exist?(File.join(destination_root, skill_file_path)) template "skills/BACKGROUND_REMOVERS.md.tt", skill_file_path end end |
#show_usage ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/generators/ruby_llm_agents/background_remover_generator.rb', line 56 def show_usage remover_class_name = name.split("/").map(&:camelize).join("::") full_class_name = "Images::#{remover_class_name}BackgroundRemover" say "" say "Background remover #{full_class_name} created!", :green say "" say "Usage:" say " # Remove background from an image" say " result = #{full_class_name}.call(image: 'photo.jpg')" say " result.url # => 'https://...' (transparent PNG)" say " result.has_alpha? # => true" say "" say " # Override settings at runtime" say " result = #{full_class_name}.call(" say " image: 'portrait.jpg'," say " alpha_matting: true," say " return_mask: true" say " )" say "" say " # Access the segmentation mask" say " result.mask_url # => 'https://...' (if return_mask was enabled)" say "" end |