diff --git a/README.md b/README.md index eff3c34..3911be8 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ You can see how it works through the simple sample code. ![Image](images/ss0_1280.png) ## Change Log +- [1.2.1 (7)] - Dec 30, 2022 `[Changed]` + - Changed the Seed UI from Stepper to TextField and the initial value from 100 to 1_000_000. - [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]` @@ -109,7 +111,7 @@ Now you can build the project, targeting to iPhone, iPad, or My Mac (Designed fo - if you encounter the memory limit issues on mobile devices, please try adding `Increase Memory Limit` and `Extended Virtual Address Space` capabilities to your App ID. This adds an entitlement to your Xcode project. - please make sure that you use the App ID which registered the capabilities, "Extended Virtual Address Space" and "Increased Memory Limit", at Developer - Identifiers site. Or Xcode displays the signing and capabilities errors. -### progress handler +### Progress handler - if you would like to handle the progress handler during generating images, please check the another repo, which shows a sample of progress-handler. @@ -130,11 +132,23 @@ important as there could be data charges or storage impact that the user might n ![Image](images/ss_4_steps.png) +### Diffusers models + +- You can use diffusers/text-to-image models on [Hugging Face Hub](https://huggingface.co/models?pipeline_tag=text-to-image&sort=downloads) . +- Convert the model you want to use to CoreML models and add them to the Xcode project. +- For example, when you use the [852wa/8528-diffusion](https://huggingface.co/852wa/8528-diffusion) model, +which is a fine-tuning model of SD v1.4, convert the models with the below command. + +```bash +% python -m python_coreml_stable_diffusion.torch2coreml --convert-unet --convert-text-encoder --convert-vae-decoder --convert-safety-checker -o sd2CoremlChunked --model-version 852wa/8528-diffusion --bundle-resources-for-swift-cli --chunk-unet --attention-implementation SPLIT_EINSUM --compute-unit CPU_AND_NE +``` + ## Related apps -- AR Diffusion Museum: It shows how to use the progress handler and displays the generating images -step by step. -- AR Wall Picture: It's a sample app that uses generated images. It displays images in Photo Library on the wall with AR. +- [AR Diffusion Museum](https://github.com/ynagatomo/ARDiffMuseum) : +It shows how to use the progress handler and displays the generating images step by step. +- [AR Wall Picture](https://github.com/ynagatomo/ARWallPicture) : +It's a sample app that uses generated images. It displays images in Photo Library on the wall with AR. ![Image](images/relatedapps.jpg) diff --git a/imggensd2.xcodeproj/project.pbxproj b/imggensd2.xcodeproj/project.pbxproj index 9838896..3fec43e 100644 --- a/imggensd2.xcodeproj/project.pbxproj +++ b/imggensd2.xcodeproj/project.pbxproj @@ -12,7 +12,7 @@ BA03C37C293D785D001426DE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BA03C37B293D785D001426DE /* 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 */; }; - BA07E4C5295530180021EC77 /* CoreMLModels in Resources */ = {isa = PBXBuildFile; fileRef = BA07E4C4295530180021EC77 /* CoreMLModels */; }; + BA1C3AAC295EE70E00D5FB42 /* CoreMLModels in Resources */ = {isa = PBXBuildFile; fileRef = BA1C3AAB295EE70E00D5FB42 /* CoreMLModels */; }; BA645DB02957E6590037BE76 /* StableDiffusion in Frameworks */ = {isa = PBXBuildFile; productRef = BA645DAF2957E6590037BE76 /* StableDiffusion */; }; /* End PBXBuildFile section */ @@ -24,7 +24,7 @@ BA03C37E293D785D001426DE /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; BA03C386293D7CE5001426DE /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; BA03C38C293D8773001426DE /* ImageGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGenerator.swift; sourceTree = ""; }; - BA07E4C4295530180021EC77 /* CoreMLModels */ = {isa = PBXFileReference; lastKnownFileType = folder; path = CoreMLModels; sourceTree = ""; }; + BA1C3AAB295EE70E00D5FB42 /* CoreMLModels */ = {isa = PBXFileReference; lastKnownFileType = folder; path = CoreMLModels; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -59,7 +59,7 @@ BA03C376293D785C001426DE /* imggensd2 */ = { isa = PBXGroup; children = ( - BA07E4C4295530180021EC77 /* CoreMLModels */, + BA1C3AAB295EE70E00D5FB42 /* CoreMLModels */, BA03C377293D785C001426DE /* imggensd2App.swift */, BA03C379293D785C001426DE /* ContentView.swift */, BA03C38C293D8773001426DE /* ImageGenerator.swift */, @@ -142,7 +142,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - BA07E4C5295530180021EC77 /* CoreMLModels in Resources */, + BA1C3AAC295EE70E00D5FB42 /* CoreMLModels in Resources */, BA03C37F293D785D001426DE /* Preview Assets.xcassets in Resources */, BA03C37C293D785D001426DE /* Assets.xcassets in Resources */, ); @@ -305,7 +305,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\""; DEVELOPMENT_TEAM = J5CY9Q9UP5; ENABLE_PREVIEWS = YES; @@ -321,7 +321,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2.0; + MARKETING_VERSION = 1.2.1; 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 = 6; + CURRENT_PROJECT_VERSION = 7; DEVELOPMENT_ASSET_PATHS = "\"imggensd2/Preview Content\""; DEVELOPMENT_TEAM = J5CY9Q9UP5; ENABLE_PREVIEWS = YES; @@ -352,7 +352,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.2.0; + MARKETING_VERSION = 1.2.1; PRODUCT_BUNDLE_IDENTIFIER = com.atarayosd.imggensd2; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/imggensd2/ContentView.swift b/imggensd2/ContentView.swift index eb2f47e..b7092e5 100644 --- a/imggensd2/ContentView.swift +++ b/imggensd2/ContentView.swift @@ -20,7 +20,8 @@ lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer ImageGenerator.GenerationParameter(prompt: prompt, negativePrompt: negativePrompt, guidanceScale: 8.0, - seed: 100, stepCount: 20, + seed: 1_000_000, + stepCount: 20, imageCount: 1, disableSafety: false) var body: some View { ScrollView { @@ -72,7 +73,7 @@ struct PromptView: View { HStack { Text("Negative Prompt:"); Spacer() } TextField("Negative Prompt:", text: $parameter.negativePrompt) .textFieldStyle(RoundedBorderTextFieldStyle()) - Stepper(value: $parameter.guidanceScale, in: 0.0...10.0, step: 0.5) { + Stepper(value: $parameter.guidanceScale, in: 0.0...40.0, step: 0.5) { Text("Guidance scale: \(parameter.guidanceScale, specifier: "%.1f") ") } Stepper(value: $parameter.imageCount, in: 1...10) { @@ -81,9 +82,21 @@ struct PromptView: View { Stepper(value: $parameter.stepCount, in: 1...100) { Text("Iteration steps: \(parameter.stepCount)") } - Stepper(value: $parameter.seed, in: 0...10000) { - Text("Seed: \(parameter.seed)") - } - }.padding() + HStack { Text("Seed:"); Spacer() } + TextField("Seed number (0 ... 4_294_967_295)", + value: $parameter.seed, + formatter: NumberFormatter()) + .textFieldStyle(RoundedBorderTextFieldStyle()) + .onSubmit { + if parameter.seed < 0 { + parameter.seed = 0 + } else if parameter.seed > UInt32.max { + parameter.seed = Int(UInt32.max) + } else { + // do nothing + } + } + } + .padding() } }