AI prompts
base on Run Stable Diffusion on Android Devices with Snapdragon NPU acceleration. Also supports CPU/GPU inference. <div align="center">
# Local Dream <img src="./assets/icon.png" width="32" alt="Local Dream">
**Android Stable Diffusion with Snapdragon NPU acceleration**
_Also supports CPU/GPU inference_
<img src="./assets/demo1.jpg" alt="App Demo" width="600">
</div>
## About this Repo
This project is **now open sourced and completely free**. Hope you enjoy it!
If you like it, please consider [sponsor](https://github.com/xororz/local-dream?tab=readme-ov-file#-support-this-project) this project.
## 🚀 Quick Start
1. **Download**: Get the APK from [Releases](https://github.com/xororz/local-dream/releases) or [Google Play](https://play.google.com/store/apps/details?id=io.github.xororz.localdream)(NSFW filtered)
2. **Install**: Install the APK on your Android device
3. **Select Models**: Open the app and download the model(s) you want to use
## ✨ Features
- 🎨 **txt2img** - Generate images from text descriptions
- 🖼️ **img2img** - Transform existing images
- 🎭 **inpaint** - Redraw selected areas of images
<div align="center">
<img src="./assets/demo2.jpg" alt="Feature Demo" width="600">
</div>
## 🔧 Build Instructions
> **Note**: Building on Linux/WSL is recommended. Other platforms are not verified.
### Prerequisites
The following tools are required for building:
- **Rust** - Install [rustup](https://rustup.rs/), then run:
```bash
rustup default stable
rustup target add aarch64-linux-android
```
- **Ninja** - Build system
- **CMake** - Build configuration
### 1. Clone Repository
```bash
git clone --recursive https://github.com/xororz/local-dream.git
```
### 2. Prepare SDKs
1. **Download QNN SDK**: Get [QNN_SDK_2.29](https://apigwx-aws.qualcomm.com/qsc/public/v1/api/download/software/qualcomm_neural_processing_sdk/v2.29.0.241129.zip) and extract
2. **Download Android NDK**: Get [Android NDK](https://developer.android.com/ndk/downloads) and extract
3. **Configure paths**:
- Update `QNN_SDK_ROOT` in `app/src/main/cpp/CMakeLists.txt`
- Update `ANDROID_NDK_ROOT` in `app/src/main/cpp/CMakePresets.json`
### 3. Build Libraries
<details>
<summary><strong>🐧 Linux</strong></summary>
```bash
cd app/src/main/cpp/
bash ./build.sh
```
</details>
<details>
<summary><strong>🪟 Windows</strong></summary>
```powershell
# Install dependencies if needed:
# winget install Kitware.CMake
# winget install Ninja-build.Ninja
# winget install Rustlang.Rustup
cd app\src\main\cpp\
# Convert patch file (install dos2unix if needed: winget install -e --id waterlan.dos2unix)
dos2unix SampleApp.patch
.\build.bat
```
</details>
<details>
<summary><strong>🍎 macOS</strong></summary>
```bash
# Install dependencies with Homebrew:
# brew install cmake rust ninja
# Fix CMake version compatibility
sed -i '' '2s/$/ -DCMAKE_POLICY_VERSION_MINIMUM=3.5/' build.sh
bash ./build.sh
```
</details>
### 4. Build APK
Open this project in Android Studio and navigate to:
**Build → Generate App Bundles or APKs → Generate APKs**
## Technical Implementation
### NPU Acceleration
- **SDK**: Qualcomm QNN SDK leveraging Hexagon NPU
- **Quantization**: W8A16 static quantization for optimal performance
- **Resolution**: Fixed 512×512 model shape
- **Performance**: Extremely fast inference speed
### CPU/GPU Inference
- **Framework**: Powered by MNN framework
- **Quantization**: W8 dynamic quantization
- **Resolution**: Flexible sizes (128×128, 256×256, 384×384, 512×512)
- **Performance**: Moderate speed with high compatibility
## NPU High Resolution Support
After downloading a 512 resolution model, you can download patches to enable 768×768 and 1024×1024 image generation. Please note that quantized high-resolution models may produce images with poor layout. We recommend first generating at 512 resolution, then using the high-resolution model for img2img (which is essentially Highres.fix). The suggested img2img denoise_strength is around 0.75.
## Device Compatibility
### NPU Acceleration Support
Compatible with devices featuring:
- **Snapdragon 8 Gen 1**
- **Snapdragon 8+ Gen 1**
- **Snapdragon 8 Gen 2**
- **Snapdragon 8 Gen 3**
- **Snapdragon 8 Elite**
> **Note**: Other devices cannot download NPU models
### CPU/GPU Support
- **RAM Requirement**: ~2GB available memory
- **Compatibility**: Most Android devices from recent years
## Available Models
Now supports importing from local SD1.5 based safetensor for CPU/GPU.
<div align="center">
| Model | Type | CPU/GPU | NPU | Clip Skip | Source |
| ------------------------ | ----- | :-----: | :-: | :-------: | ----------------------------------------------------------------------------------- |
| **Anything V5.0** | SD1.5 | ✅ | ✅ | 2 | [CivitAI](https://civitai.com/models/9409?modelVersionId=30163) |
| **ChilloutMix** | SD1.5 | ✅ | ✅ | 1 | [CivitAI](https://civitai.com/models/6424/chilloutmix?modelVersionId=11732) |
| **Absolute Reality** | SD1.5 | ✅ | ✅ | 2 | [CivitAI](https://civitai.com/models/81458?modelVersionId=132760) |
| **QteaMix** | SD1.5 | ✅ | ✅ | 2 | [CivitAI](https://civitai.com/models/50696/qteamix-q?modelVersionId=94654) |
| **CuteYukiMix** | SD1.5 | ✅ | ✅ | 2 | [CivitAI](https://civitai.com/models/28169?modelVersionId=265102) |
| **Stable Diffusion 2.1** | SD2.1 | ❌ | ✅ | 1 | [HuggingFace](https://huggingface.co/stabilityai/stable-diffusion-2-1/tree/main) |
| **Pony V5.5** | SD2.1 | ❌ | ✅ | 1 | [CivitAI](https://civitai.com/models/95367/pony-diffusion-v5?modelVersionId=205936) |
</div>
## 🎲 Seed Settings
Custom seed support for reproducible image generation:
- **CPU Mode**: Seeds guarantee identical results across different devices with same parameters
- **GPU Mode**: Results may differ from CPU mode and can vary between different devices
- **NPU Mode**: Seeds ensure consistent results only on devices with identical chipsets
## Credits & Acknowledgments
### C++ Libraries
- **[Qualcomm QNN SDK](https://www.qualcomm.com/developer/software/neural-processing-sdk-for-ai)** - NPU model execution
- **[alibaba/MNN](https://github.com/alibaba/MNN/)** - CPU model execution
- **[xtensor-stack](https://github.com/xtensor-stack)** - Tensor operations & scheduling
- **[mlc-ai/tokenizers-cpp](https://github.com/mlc-ai/tokenizers-cpp)** - Text tokenization
- **[yhirose/cpp-httplib](https://github.com/yhirose/cpp-httplib)** - HTTP server
- **[nothings/stb](https://github.com/nothings/stb)** - Image processing
- **[facebook/zstd](https://github.com/facebook/zstd)** - Model compression
- **[nlohmann/json](https://github.com/nlohmann/json)** - JSON processing
### Android Libraries
- **[coil-kt/coil](https://github.com/coil-kt/coil)** - Image loading & processing
- **[MoyuruAizawa/Cropify](https://github.com/MoyuruAizawa/Cropify)** - Image cropping
- **AOSP, Material Design, Jetpack Compose** - UI framework
### NSFW Detection Model
- **[bhky/opennsfw2](https://github.com/bhky/opennsfw2)** - NSFW content filtering
---
## 💖 Support This Project
If you find Local Dream useful, please consider supporting its development:
### What Your Support Helps With:
- **Additional Models** - More AI model integrations
- **New Features** - Enhanced functionality and capabilities
- **Bug Fixes** - Continuous improvement and maintenance
<a href="https://ko-fi.com/xororz">
<img height="36" style="border:0px;height:36px;" src="https://storage.ko-fi.com/cdn/kofi2.png?v=3" border="0" alt="Buy Me a Coffee at ko-fi.com" />
</a>
<a href="https://afdian.com/a/xororz">
<img height="36" style="border-radius:12px;height:36px;" src="https://pic1.afdiancdn.com/static/img/welcome/button-sponsorme.jpg" alt="在爱发电支持我" />
</a>
Your sponsorship helps maintain and improve Local Dream for everyone!
</div>
", Assign "at most 3 tags" to the expected json: {"id":"14782","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"