{"id":13493475,"url":"https://github.com/nimadez/mental-diffusion","last_synced_at":"2025-04-28T16:12:17.872Z","repository":{"id":169983361,"uuid":"646072414","full_name":"nimadez/mental-diffusion","owner":"nimadez","description":"Fast Stable Diffusion CLI","archived":true,"fork":false,"pushed_at":"2024-10-05T08:17:22.000Z","size":2812,"stargazers_count":108,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-28T16:12:11.197Z","etag":null,"topics":["command-line","diffusers","generative-ai","gradio","headless","huggingface","img2img","inpaint","machine-learning","realesrgan","safetensors","sdxl","stable-diffusion","transformers","txt2img","upscaler"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nimadez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-27T07:36:20.000Z","updated_at":"2025-04-17T09:43:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"9492287d-d7a3-403a-8099-a605fa241e5d","html_url":"https://github.com/nimadez/mental-diffusion","commit_stats":null,"previous_names":["nimadez/diffusion","nimadez/mental-diffusion"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimadez%2Fmental-diffusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimadez%2Fmental-diffusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimadez%2Fmental-diffusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nimadez%2Fmental-diffusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nimadez","download_url":"https://codeload.github.com/nimadez/mental-diffusion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251342725,"owners_count":21574245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","diffusers","generative-ai","gradio","headless","huggingface","img2img","inpaint","machine-learning","realesrgan","safetensors","sdxl","stable-diffusion","transformers","txt2img","upscaler"],"created_at":"2024-07-31T19:01:15.594Z","updated_at":"2025-04-28T16:12:17.851Z","avatar_url":"https://github.com/nimadez.png","language":"Python","readme":"## Mental Diffusion\n\n\u003e **Notice**: The experiment is over and this repository is for learning purposes.\n\n**Fast Stable Diffusion CLI**\n\n| [MDX](https://github.com/nimadez/mental-diffusion/blob/main/src/mdx.py) | 0.9.5 |\n| ------- | --- |\n| Python | 3.11 - 3.12 |\n| Torch | +cu121 |\n| Diffusers | 0.30.2 |\n| + Gradio | 4.42.0 |\n\n\u003e The **mdx.py** script is tested-stable.\n\n## Features\n- SD, **SDXL**\n- Load VAE and LoRA weights\n- Txt2Img, Img2Img, Inpaint *(auto-pipeline)*\n- TAESD latents preview *(image and animation)*\n- Batch image generation, multiple images per prompt\n- Read/write PNG metadata, auto-rename files\n- CPU, GPU, Low VRAM mode *(load SDXL with 4 GB)*\n- Lightweight and fast, rewritten in **300** lines\n- Proxy, offline mode, minimal downloads\n- Gradio [user-interface](https://github.com/nimadez/mental-diffusion/?tab=readme-ov-file#user-interface) *(mdx-ui.py)*\n- Real-ESRGAN x2 and x4 script *(mdx-upscale.py)*\n\n## Installation\n\u003e - 3.5 GB python packages (5.5 GB extracted)\n\u003e - Compatible with most diffusers-based python venvs\n\u003e - Make sure you have a swap partition or swap file\n```\ngit clone https://github.com/nimadez/mental-diffusion\ncd mental-diffusion\n\n# Automatic installation:\nsudo apt install python3-pip python3-venv\nsh install-venv.sh\n\n# Manual installation:\npython3 -m venv ~/.venv/mdx\nsource ~/.venv/mdx/bin/activate\npip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu121\npip install -r ./requirements.txt\ndeactivate\n```\nInstall Gradio and Zenity for user-interface:\n```\n~/.venv/mdx/bin/python3 -m pip install gradio==4.42.0\nsudo apt install zenity\n\n* Zenity: If you don't have a GNOME desktop, you can't use the file dialog to select .safetensors files, you have to enter the Checkpoint, LoRA and VAE path manually.\n```\n\n## Arguments\n```\n~/.venv/mdx/bin/python3 mdx.py --help\n\n--type        -t    str     sd, xl (def: custom)\n--checkpoint  -c    str     /checkpoint.safetensors (def: custom)\n--scheduler   -sc   str     ddim, ddpm, euler, eulera, lcm, lms, pndm (def: custom)\n--prompt      -p    str     positive prompt\n--negative    -n    str     negative prompt\n--width       -w    int     divisible by 8 (def: custom)\n--height      -h    int     divisible by 8 (def: custom)\n--seed        -s    int     -1 randomize (def: -1)\n--steps       -st   int     1 to 100+ (def: 24)\n--guidance    -g    float   0 - 20.0+ (def: 8.0)\n--strength    -sr   float   0 - 1.0 (def: 1.0)\n--lorascale   -ls   float   0 - 1.0 (def: 1.0)\n--image       -i    str     /image.png\n--mask        -m    str     /mask.png\n--vae         -v    str     /vae.safetensors\n--lora        -l    str     /lora.safetensors\n--filename    -f    str     filename prefix without .png extension, add {seed} to be replaced (def: img_{seed})\n--output      -o    str     image and preview output directory (def: custom)\n--number      -no   int     number of images to generate per prompt (def: 1)\n--batch       -b    int     number of repeats to run in batch, --seed -1 to randomize\n--preview     -pv           stepping is slower with preview enabled (def: no preview)\n--lowvram     -lv           slower if you have enough VRAM, automatic on 4GB cards (def: no lowvram)\n--metadata    -meta str     /image.png, extract metadata from png\n\n[automatic pipeline]\nTxt2Img: no --image and no --mask\nImg2Img: --image and no --mask\nInpaint: --image and --mask\nERROR:   no --image and --mask\n```\n```\nDefault:    mdx -p \"prompt\" -st 28 -g 7.5\nSD:         mdx -t sd -c /checkpoint.safetensors -w 512 -h 512\nSDXL:       mdx -t xl -c /checkpoint.safetensors -w 768 -h 768\nImg2Img:    mdx -i /image.png -sr 0.5\nInpaint:    mdx -i /image.png -m ./mask.png\nVAE:        mdx -v /vae.safetensors\nLoRA:       mdx -l /lora.safetensors -ls 0.5\nFilename:   mdx -f img_test_{seed}\nOutput:     mdx -o /home/user/.mdx\nNumber:     mdx -no 4\nBatch:      mdx -b 10\nPreview:    mdx -pv\nLow VRAM:   mdx -lv\nMetadata:   mdx -meta ./image.png\n\nmdx-upscale --help\nmdx-upscale -i ./image.png\nmdx-upscale -i ./image.png -m x2\nmdx-upscale -i ./image.png -m x4 -o ~/Downloads\n```\n\n## User Interface\n```\n~/.venv/mdx/bin/python3 src/mdx-ui.py\nsh mdx-ui\nsh mdx-ui-dev   # development mode (auto reload)\nopen http://localhost:8011\n```\n\n\u003cimg src=\"media/webui.png\"\u003e\n\n## Direct Inference\nImport MDX class to inference from JSON data\n\n```\nfrom mdx import MDX\n\ndata = json.loads(data)\ndata[\"prompt\"] = \"new prompt\"\n\nparser = argparse.ArgumentParser()\nargs = parser.parse_args(namespace=argparse.Namespace(**data))\n\nMDX().main(args)\n```\n\u003e Inference can be interrupted by creating a file named \".interrupt\" in the --output directory. (e.g. mdx-ui.py)\n\n## Tips \u0026 Tricks\n```\n* Enable OFFLINE if you have already downloaded the huggingface cache\n* Enable SAVE_ANIM to save the preview animation to {output}/filename.webp\n* Model may be slow to load on first launch, but reloading SDXL with 4GB only takes a second\n\nPreview, cancel, and repeat faster:\nmdx -p \"prompt\" -g 8.0 -st 30 -pv\nmdx -p \"prompt\" -g 8.0 -st 30 -s 827362763262387\n\nContent-aware upscaling: (ImageMagick)\nmdx -p \"prompt\" -st 20 -w 512 -h 512 -f image\nmagick convert ~/.mdx/image.png -resize 200% ~/.mdx/image_up.png\nmdx -p \"prompt\" -st 20 -i ~/.mdx/image_up.png -sr 0.5\n\nGenerate 40 images in less time:\nmdx -p \"prompt\" -b 10 -no 4\n\nExtract images from WebP animation: (ImageMagick)\nmagick convert image.webp jpg\n\nExplore output directory in a browser across the LAN:\ncd ~/.mdx \u0026\u0026 python3 -m http.server 8000\n$ open http://192.168.x.x:8000\n\nDownload huggingface cache in a specific path:\nmkdir ~/.hfcache \u0026\u0026 ln -s ~/.hfcache ~/.cache/huggingface\n```\n\n## Previous Experiments\n\u003cimg src=\"legacy/media/preview.gif\"\u003e\n\n\u003e - [Legacy command-line interface and server](https://github.com/nimadez/mental-diffusion/tree/main/legacy/README.md) (diffusers)\n\u003e - [ComfyUI bridge for VS Code extension](https://github.com/nimadez/mental-diffusion/tree/main/comfyui/README.md)\n\n## History\n```\n↑ Add Gradio user-interface\n↑ Rewritten in 300 lines\n↑ Port to Linux\n↑ Back to Diffusers\n↑ Port to Code (webui)\n↑ Change to ComfyUI API (webui)\n↑ Created for personal use (diffusers)\n\n\"AI will bring us back to the age of terminals.\"\n```\n\n## License\nCode released under the [MIT license](https://github.com/nimadez/mental-diffusion/blob/main/LICENSE).\n\n## Credits\n- [Hugging Face](https://huggingface.co/)\n- [Diffusers](https://github.com/huggingface/diffusers)\n- [Transformers](https://github.com/huggingface/transformers)\n- [PyTorch](https://pytorch.org/)\n- [Stability-AI](https://github.com/Stability-AI)\n- [TAESD](https://github.com/madebyollin/taesd)\n- [Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)\n- [Gradio](https://www.gradio.app/)\n\n##### Models\n- zavychromaxl_v80\n- OpenDalleV1.1\n- juggernaut_aftermath\n","funding_links":[],"categories":["Python","Projects using ComfyUI"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnimadez%2Fmental-diffusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnimadez%2Fmental-diffusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnimadez%2Fmental-diffusion/lists"}