Skip to content

Commit

Permalink
Removes image optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
apmiller108 committed Jan 21, 2025
1 parent 8c18661 commit 74c984e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
1 change: 1 addition & 0 deletions TODO.org
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,4 @@ CLOSED: [2025-01-20 Mon 13:49]
* TODO Move the aws invoke model response
- [ ] Write a shared example the enforce the interface
https://morningcoffee.io/interfaces-in-ruby.html
* TODO look into using https://runware.ai/
21 changes: 1 addition & 20 deletions app/models/generate_text_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ class GenerateTextRequest < ApplicationRecord
TEMPERATURE_VALUES = 0.step(to: 1, by: 0.1).map { _1.round(1) }

SUPPORTED_MIME_TYPES = %w[image/jpeg image/gif image/png/ image/webp].freeze
has_one_attached :file do |attachable|
attachable.variant :for_display, { resize_to_limit: [1920, 1920],
preprocessed: true,
**ActiveStorage::Blob::WEBP_VARIANT_OPTS }
end
before_save :optimize_image, if: -> { file.attached? && file_changed? && file.blob.image? }
has_one_attached :file

# Stores the raw JSON response from the HTTP request to the LLM
store_accessor :response
Expand Down Expand Up @@ -73,18 +68,4 @@ def acceptable_file
errors.add(:file, 'must be less that 10 MB') if file.blob.byte_size > 10.megabytes
errors.add(:file, 'must be GIF, JPEG, PNG or WEBP') unless file.blob.content_type.in? SUPPORTED_MIME_TYPES
end

def optimize_image
return unless file.blob.image?

processed_image = file.variant(
resize_to_limit: [1920, 1920],
saver: {
strip: true,
quality: 80
}
).processed

file.attach(processed_image.blob)
end
end

0 comments on commit 74c984e

Please sign in to comment.