npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-stable-diffusion

v0.2.0

Published

Run Stable Diffusion using Core ML on iOS & iPadOS within your Expo & React Native App

Downloads

3

Readme

expo-stable-diffusion

GitHub last commit npm GitHub issues GitHub stars

Read The Full Detailed Guide

❗️ expo-stable-diffusion currently only works on iOS due to the platform's ability to run Stable Diffusion models on Apple Neural Engine!

❗️ This package is not included in the Expo Go. You will have to use a Development Build or build it locally using Xcode!

Introduction

Start by installing the expo-stable-diffusion module into your Expo managed project:

npx expo install expo-stable-diffusion

Configuration

Update iOS Deployment Target

In order for the project to build successfully, you have to set the iOS Deployment Target to 16.2. You can achieve this by installing the expo-build-properties plugin:

npx expo install expo-build-properties

Configure the plugin by adding the following to your app.json:

{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "deploymentTarget": "16.2"
          }
        }
      ]
    ]
  }
}

Enable Increased Memory Limit

To prevent memory issues, add the Increased Memory Limit capability to your iOS project. Add the following to your app.json:

{
  "expo": {
    "ios": {
      "entitlements": {
        "com.apple.developer.kernel.increased-memory-limit": true
      }
    }
  }
}

Build Your iOS App

npx expo prebuild --clean --platform ios
npx expo run:ios

Usage

After installation and configuration, you can start generating images using expo-stable-diffusion. Here's a basic example:

import * as FileSystem from "expo-file-system";
import * as ExpoStableDiffusion from "expo-stable-diffusion";

const MODEL_PATH = FileSystem.documentDirectory + "Model/stable-diffusion-2-1";
const SAVE_PATH = FileSystem.documentDirectory + "image.jpeg";

await ExpoStableDiffusion.loadModel(MODEL_PATH);

await ExpoStableDiffusion.generateImage({
  prompt: "a cat coding at night",
  stepCount: 25,
  savePath: SAVE_PATH,
});

const subscription = ExpoStableDiffusion.addStepListener(({ step }) => {
  console.log(`Current Step: ${step}`);
});

return () => subscription.remove();

💡 If you are saving the image in a custom directory, make sure that the directory actually exists or you can create it using FileSystem.makeDirectoryAsync(fileUri, options).

Obtaining Stable Diffusion Models

To use the expo-stable-diffusion module, you need a converted Core ML Stable Diffusion model. You can convert your own model using Apple's official guide or download pre-converted models from Apple's Hugging Face repository or my Hugging Face repository.

Troubleshooting

❗️ The model load time and image generation duration take some time, especially on devices with lower RAM than 6GB! Find more information in Q6 in the FAQ section of the ml-stable-diffusion repo.

Running Stable Diffusion on Lower-End Devices

failed to load ANE model