Skip to content

Commit

Permalink
feat: Image Styles w/ SD
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarMWarraich committed Jun 28, 2024
1 parent b0a7602 commit 28b48d3
Show file tree
Hide file tree
Showing 4 changed files with 493 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/controllers/txt2_imgs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
class Txt2ImgsController < ApplicationController
def index

@styles = Styles.load

api_instance = RStableDiffusionAI::DefaultApi.new
result = api_instance.get_sd_models_sdapi_v1_sd_models_get
@models = result.map { |model| model.model_name }
end

def create
style = Styles.find_by_name(params[:style_template])
style = { name: '++ None', prompt: '{prompt}', negative_prompt: '' } if style.nil?

prompt = params[:prompt]
merged_prompt = style[:prompt].gsub('{prompt}', prompt)
merged_negative_prompt = [style[:negative_prompt], image_maker_params[:negative_prompt]].compact.join(', ')

sd_settings = {
original_prompt: image_create_params[:prompt],
prompt: merged_prompt,
negative_prompt: merged_negative_prompt,
sampler_name: 'DPM++ 2M Karras',
override_settings: { sd_model_checkpoint: image_create_params.delete(:sd_model) }
}.deep_symbolize_keys

new_settings = image_create_params.to_h.deep_symbolize_keys.merge(sd_settings)
end

private

def image_create_params
params.require(:image_maker).permit(:prompt, :style_template)
end
end
2 changes: 1 addition & 1 deletion app/views/txt2_imgs/_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= form.label :style_template, "Style", class: "form-label" %>
</div>
<div class='col'>
<%= form.select :style_template, [], {}, {class: "form-select w-100"} %>
<%= form.select :style_template, @styles.map { |s| [s[:name].titleize, s[:name]] }.sort, { include_blank: true }, {class: "form-select w-100"} %>
</div>
</div>

Expand Down
Loading

0 comments on commit 28b48d3

Please sign in to comment.