Skip to content

Running Stable diffusion from a mobile phone using Termux

Notifications You must be signed in to change notification settings

zehr0s/mobile-stable-diffusion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Showcase

Usage

The script text2image_cli.py <demo> accepts an optional argument (demo) to run with a default configuration.

# Login to linux distro
proot-distro login debian --shared-tmp
# Load python venv
source .venv/bin/activate
# Run script
cd mobile-stable-diffusion
python text2image_cli.py demo

Results

This is the configuration used for this example.

{
  "modelName": "meinamix_meinaV9",
  "prompt": "(masterpiece, best quality, high quality, highresolution:1.4), ambient soft lighting, 4K, 1girl,cute,huge breasts,close-up,long hair,pink hair,black hairband,pink eyes, well defined nose, happy, close-up,((gradient hair))",
  "negativePrompt": "easynegative, badhandv4, (worst quality, low quality, normal quality), bad-artist, blurry, ugly, ((bad anatomy)),((bad hands)),((bad proportions)),((duplicate limbs)),((fused limbs)),((interlocking fingers)),((poorly drawn face)),clothes,logo,watermark,muscles:1.3,elf,elf ears,headphones,",
  "width": 320,
  "height": 320,
  "seed": 78583
}

Some outputs with different steps.

Steps DPMSolverMultistepScheduler EulerDiscreteScheduler
20 Image Image
32 Image Image
64 Image Image

See other results and configurations here.

Intro

To use stable diffusion you'll need Termux, this app allows you to use a linux distro in your mobile phone.

You'll also need a model to work with. In this case I'll be MeinaMix a model hosted in Civitai and HuggingFace.

I usually generate the model form a .safetensors file or download the files directly from a HuggingFace repo.

The model should be placed inside the Models folder and have the following structure:

Models/meinamix_meinaV9
├── feature_extractor
│   └── preprocessor_config.json
├── model_index.json
├── safety_checker
│   ├── config.json
│   └── pytorch_model.bin
├── scheduler
│   └── scheduler_config.json
├── text_encoder
│   ├── config.json
│   └── pytorch_model.bin
├── tokenizer
│   ├── merges.txt
│   ├── special_tokens_map.json
│   ├── tokenizer_config.json
│   └── vocab.json
├── unet
│   ├── config.json
│   └── diffusion_pytorch_model.bin
└── vae
    ├── config.json
    └── diffusion_pytorch_model.bin

Set up

Download Termux and install it on your phone.

Install a linux distro

pkg install proot
pkg install proot-debian
pkg install proot-distro
proot-distro install debian

Note that the distro will be located at /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/debian/root.

Login to the linux distro

proot-distro login debian --shared-tmp

Install dependencies

apt update
apt install git git-lfs vim python3 python3-pip python3-venv

Python venv

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade diffusers transformers accelerate ftfy xformers
pip install pytorch
pip install torch

Clone repo

git clone https://github.com/zehr0s/mobile-stable-diffusion
cd mobile-stable-diffusion

Download model

Download the model and place it inside the folder Models.

Run the script

python text2image_cli.py

Releases

No releases published

Packages

No packages published

Languages