adapted to apple/v0.2.0

main
Yasuhito Nagatomo 1 year ago
parent 2e4d996fc0
commit 9543b2d742

@ -25,6 +25,9 @@ You can see how it works through the simple sample code.
![Image](images/ss0_1280.png)
## Change Log
- [1.3.0 (9)] - Feb 10, 2023 `[Changed]`
- Changed to use the Configuration structure when calling the generateImages(configuration: progressHandler:) API to support changes in the API of apple/ml-stable-diffusion v0.2.0.
- The apple/ml-stable-diffusion Swift Package v0.2.0 or later is required.
- [1.2.2 (8)] - Jan 16, 2023 `[Changed]`
- Commented out the specifying the MLModelConfiguration.computeUnits and changed it to use the default,
because it is not necessary.

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

@ -6,7 +6,7 @@
"location" : "https://github.com/apple/ml-stable-diffusion#swift-requirements",
"state" : {
"branch" : "main",
"revision" : "e07c4d00c387840f70fa3701fb3a51c2a32f37b8"
"revision" : "00390a64182ddd87ef368f70f3a2de9acd26cb29"
}
},
{

@ -116,13 +116,29 @@ final class ImageGenerator: ObservableObject {
// please check the another repo - AR Diffusion Museum:
// https://github.com/ynagatomo/ARDiffMuseum
// It handles the progressHandler and displays the generating images step by step.
let cgImages = try sdPipeline.generateImages(prompt: parameter.prompt,
negativePrompt: parameter.negativePrompt,
imageCount: parameter.imageCount,
stepCount: parameter.stepCount,
seed: UInt32(parameter.seed),
guidanceScale: parameter.guidanceScale,
disableSafety: parameter.disableSafety)
// at v1.3.0
// apple/ml-stable-diffusion v0.2.0 changed the generateImages() API
// to generateImages(configuration:progressHandler:)
// let cgImages = try sdPipeline.generateImages(prompt: parameter.prompt,
// negativePrompt: parameter.negativePrompt,
// imageCount: parameter.imageCount,
// stepCount: parameter.stepCount,
// seed: UInt32(parameter.seed),
// guidanceScale: parameter.guidanceScale,
// disableSafety: parameter.disableSafety)
// Mode: textToImage or imageToImage
// when startingImage != nil AND strength < 1.0, imageToImage mode is selected
var configuration = StableDiffusionPipeline.Configuration(prompt: parameter.prompt)
configuration.negativePrompt = parameter.negativePrompt
configuration.imageCount = parameter.imageCount
configuration.stepCount = parameter.stepCount
configuration.seed = UInt32(parameter.seed)
configuration.guidanceScale = parameter.guidanceScale
configuration.disableSafety = parameter.disableSafety
let cgImages = try sdPipeline.generateImages(configuration: configuration)
print("images were generated.")
let uiImages = cgImages.compactMap { image in
if let cgImage = image { return UIImage(cgImage: cgImage)

Loading…
Cancel
Save