added the guidance scale.

main
Yasuhito Nagatomo 2 years ago
parent 6dd439fc06
commit a8928ce569

@ -25,6 +25,8 @@ You can see how it works through the simple sample code.
![Image](images/ss0_1280.png) ![Image](images/ss0_1280.png)
## Change Log ## Change Log
- [1.2.0 (6)] - Dec 25, 2022 `[Added]`
- Added the guidance scale. It requires the latest apple/ml-stable-diffusion Swift Package.
- [1.1.0 (5)] - Dec 21, 2022 `[Added]` - [1.1.0 (5)] - Dec 21, 2022 `[Added]`
- Added the negative prompt. It requires the latest apple/ml-stable-diffusion Swift Package. - Added the negative prompt. It requires the latest apple/ml-stable-diffusion Swift Package.
- [1.0.3 (4)] - Dec 18, 2022 `[Changed]` - [1.0.3 (4)] - Dec 18, 2022 `[Changed]`

@ -13,7 +13,7 @@
BA03C37F293D785D001426DE /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37E293D785D001426DE /* Preview Assets.xcassets */; }; BA03C37F293D785D001426DE /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37E293D785D001426DE /* Preview Assets.xcassets */; };
BA03C38D293D8773001426DE /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C38C293D8773001426DE /* ImageGenerator.swift */; }; BA03C38D293D8773001426DE /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03C38C293D8773001426DE /* ImageGenerator.swift */; };
BA07E4C5295530180021EC77 /* CoreMLModels in Resources */ = {isa = PBXBuildFile; fileRef = BA07E4C4295530180021EC77 /* CoreMLModels */; }; BA07E4C5295530180021EC77 /* CoreMLModels in Resources */ = {isa = PBXBuildFile; fileRef = BA07E4C4295530180021EC77 /* CoreMLModels */; };
BA1E84232952ED66001701EA /* StableDiffusion in Frameworks */ = {isa = PBXBuildFile; productRef = BA1E84222952ED66001701EA /* StableDiffusion */; }; BA645DB02957E6590037BE76 /* StableDiffusion in Frameworks */ = {isa = PBXBuildFile; productRef = BA645DAF2957E6590037BE76 /* StableDiffusion */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
@ -32,7 +32,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
BA1E84232952ED66001701EA /* StableDiffusion in Frameworks */, BA645DB02957E6590037BE76 /* StableDiffusion in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -95,7 +95,7 @@
); );
name = imggensd2; name = imggensd2;
packageProductDependencies = ( packageProductDependencies = (
BA1E84222952ED66001701EA /* StableDiffusion */, BA645DAF2957E6590037BE76 /* StableDiffusion */,
); );
productName = imggensd2; productName = imggensd2;
productReference = BA03C374293D785C001426DE /* imggensd2.app */; productReference = BA03C374293D785C001426DE /* imggensd2.app */;
@ -126,7 +126,7 @@
); );
mainGroup = BA03C36B293D785C001426DE; mainGroup = BA03C36B293D785C001426DE;
packageReferences = ( packageReferences = (
BA1E84212952ED66001701EA /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */, BA645DAE2957E6590037BE76 /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */,
); );
productRefGroup = BA03C375293D785C001426DE /* Products */; productRefGroup = BA03C375293D785C001426DE /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -305,7 +305,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\"";
DEVELOPMENT_TEAM = J5CY9Q9UP5; DEVELOPMENT_TEAM = J5CY9Q9UP5;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@ -321,7 +321,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.1.0; MARKETING_VERSION = 1.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2; PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
@ -336,7 +336,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\"";
DEVELOPMENT_TEAM = J5CY9Q9UP5; DEVELOPMENT_TEAM = J5CY9Q9UP5;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
@ -352,7 +352,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.1.0; MARKETING_VERSION = 1.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2; PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
@ -385,9 +385,9 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */
BA1E84212952ED66001701EA /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */ = { BA645DAE2957E6590037BE76 /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */ = {
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/ml-stable-diffusion"; repositoryURL = "https://github.com/apple/ml-stable-diffusion#swift-requirements";
requirement = { requirement = {
branch = main; branch = main;
kind = branch; kind = branch;
@ -396,9 +396,9 @@
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */ /* Begin XCSwiftPackageProductDependency section */
BA1E84222952ED66001701EA /* StableDiffusion */ = { BA645DAF2957E6590037BE76 /* StableDiffusion */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
package = BA1E84212952ED66001701EA /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */; package = BA645DAE2957E6590037BE76 /* XCRemoteSwiftPackageReference "ml-stable-diffusion" */;
productName = StableDiffusion; productName = StableDiffusion;
}; };
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */

@ -1,12 +1,12 @@
{ {
"pins" : [ "pins" : [
{ {
"identity" : "ml-stable-diffusion", "identity" : "ml-stable-diffusion#swift-requirements",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",
"location" : "https://github.com/apple/ml-stable-diffusion", "location" : "https://github.com/apple/ml-stable-diffusion#swift-requirements",
"state" : { "state" : {
"branch" : "main", "branch" : "main",
"revision" : "c90b705334c3807f4f4042cbb351b59cbe5c6f7b" "revision" : "e07c4d00c387840f70fa3701fb3a51c2a32f37b8"
} }
}, },
{ {

@ -19,6 +19,7 @@ lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer
@State private var generationParameter = @State private var generationParameter =
ImageGenerator.GenerationParameter(prompt: prompt, ImageGenerator.GenerationParameter(prompt: prompt,
negativePrompt: negativePrompt, negativePrompt: negativePrompt,
guidanceScale: 8.0,
seed: 100, stepCount: 20, seed: 100, stepCount: 20,
imageCount: 1, disableSafety: false) imageCount: 1, disableSafety: false)
var body: some View { var body: some View {
@ -71,6 +72,9 @@ struct PromptView: View {
HStack { Text("Negative Prompt:"); Spacer() } HStack { Text("Negative Prompt:"); Spacer() }
TextField("Negative Prompt:", text: $parameter.negativePrompt) TextField("Negative Prompt:", text: $parameter.negativePrompt)
.textFieldStyle(RoundedBorderTextFieldStyle()) .textFieldStyle(RoundedBorderTextFieldStyle())
Stepper(value: $parameter.guidanceScale, in: 0.0...10.0, step: 0.5) {
Text("Guidance scale: \(parameter.guidanceScale, specifier: "%.1f") ")
}
Stepper(value: $parameter.imageCount, in: 1...10) { Stepper(value: $parameter.imageCount, in: 1...10) {
Text("Image Count: \(parameter.imageCount)") Text("Image Count: \(parameter.imageCount)")
} }

@ -14,6 +14,7 @@ final class ImageGenerator: ObservableObject {
struct GenerationParameter { struct GenerationParameter {
var prompt: String var prompt: String
var negativePrompt: String var negativePrompt: String
var guidanceScale: Float
var seed: Int var seed: Int
var stepCount: Int var stepCount: Int
var imageCount: Int var imageCount: Int
@ -28,6 +29,7 @@ final class ImageGenerator: ObservableObject {
struct GeneratedImages { struct GeneratedImages {
let prompt: String let prompt: String
let negativePrompt: String let negativePrompt: String
let guidanceScale: Float
let imageCount: Int let imageCount: Int
let stepCount: Int let stepCount: Int
let seed: Int let seed: Int
@ -72,6 +74,7 @@ final class ImageGenerator: ObservableObject {
generatedImages = images generatedImages = images
} }
// swiftlint:disable function_body_length
func generateImages(_ parameter: GenerationParameter) { func generateImages(_ parameter: GenerationParameter) {
guard generationState == .idle else { return } guard generationState == .idle else { return }
Task.detached(priority: .high) { Task.detached(priority: .high) {
@ -111,6 +114,7 @@ final class ImageGenerator: ObservableObject {
imageCount: parameter.imageCount, imageCount: parameter.imageCount,
stepCount: parameter.stepCount, stepCount: parameter.stepCount,
seed: UInt32(parameter.seed), seed: UInt32(parameter.seed),
guidanceScale: parameter.guidanceScale,
disableSafety: parameter.disableSafety) disableSafety: parameter.disableSafety)
print("images were generated.") print("images were generated.")
let uiImages = cgImages.compactMap { image in let uiImages = cgImages.compactMap { image in
@ -119,6 +123,7 @@ final class ImageGenerator: ObservableObject {
} }
await self.setGeneratedImages(GeneratedImages(prompt: parameter.prompt, await self.setGeneratedImages(GeneratedImages(prompt: parameter.prompt,
negativePrompt: parameter.negativePrompt, negativePrompt: parameter.negativePrompt,
guidanceScale: parameter.guidanceScale,
imageCount: parameter.imageCount, imageCount: parameter.imageCount,
stepCount: parameter.stepCount, stepCount: parameter.stepCount,
seed: parameter.seed, seed: parameter.seed,

Loading…
Cancel
Save