Studio Ghibli’s magical worlds and hand-painted aesthetics have inspired artists worldwide. With advancements in AI, you can now generate Studio Ghibli-style art using Stable Diffusion on your own computer! This guide will show you how to set up a Studio Ghibli art generator locally on an M1/M2 Mac with Apple’s Metal (MPS) acceleration.


Why Run It Locally?
✅ No internet required** – Your AI model runs on your computer.

✅ Faster performance** – Take full advantage of Apple’s Metal API.

✅ No API limits or fees** – Unlike online tools, you can generate unlimited art.

✅ More control** – Fine-tune results by adjusting model parameters.


Step 1: Install Dependencies

First, open Terminal and install the required Python libraries:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install diffusers transformers accelerate safetensors pillow tk

Why these dependencies?**

  • torch: Provides PyTorch’s machine learning framework.
  • diffusers: Handles Stable Diffusion models.
  • transformers: Enables text-to-image generation.
  • pillow: Processes images.
  • tk: Allows for an easy file upload interface.

Step 2: Download a Studio Ghibli Model (Optional)**

Stable Diffusion models trained specifically on Studio Ghibli aesthetics provide better results than the standard model. You can find one on CivitAI or Hugging Face.

To use a custom model, download the .safetensors file and save it in a directory, e.g., ~/models/ghibli_model/.


Step 3: Run the Studio Ghibli Art Generator**

Save the following Python script as ghibli_generator.py:

import torch
import tkinter as tk
from tkinter import filedialog
from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image

# ✅ Set device to MPS (Apple Metal) for best performance
device = "mps" if torch.backends.mps.is_available() else "cpu"

# ✅ Load the Stable Diffusion model (Replace with Ghibli model path if needed)
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-1",  # Use a custom Ghibli model if available
    torch_dtype=torch.float32
).to(device)

# ✅ Open file dialog to select an image
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(title="Select an image", filetypes=[("Image files", "*.png;*.jpg;*.jpeg")])

if not file_path:
    print("❌ No file selected. Exiting...")
    exit()

# ✅ Load the user-selected image
init_image = Image.open(file_path).convert("RGB").resize((512, 512))

# ✅ Define the AI transformation prompt
prompt = "A beautiful Studio Ghibli-style landscape with vibrant colors and soft lighting"

# ✅ Generate AI-modified image
generator = torch.manual_seed(42)
output_image = pipe(
    prompt=prompt,
    image=init_image,
    strength=0.75,  # Higher means more AI influence
    guidance_scale=7.5  # Controls how closely AI follows the prompt
).images[0]

# ✅ Save and show the generated image
output_image.save("ghibli_output.png")
output_image.show()
print("✅ Image saved as ghibli_output.png")

Step 4: Run the Script**

Once the script is saved, open Terminal, navigate to the folder, and run:

python ghibli_generator.py

How It Works:

  1. A file selection dialog will open—choose an image.
  2. The AI will modify the image in Studio Ghibli’s art style.
  3. The generated image will be saved as ghibli_output.png.
  4. The result will open automatically for preview.

Step 5: Fine-Tune the AI Output**

Here are some tweaks you can make to get the perfect Ghibli-style output:

🔹 Use a Different Prompt
Modify the prompt variable in the script to get different styles:

prompt = "A peaceful Ghibli-style countryside with warm pastel colors"

🔹 Adjust Strength for AI Control

  • Lower values (0.3-0.5) keep more details from the original image.
  • Higher values (0.7-1.0) make the AI modify it more.
strength = 0.6  # Try reducing if too much detail is lost

🔹 Use a Custom Ghibli Model
If you downloaded a Studio Ghibli-trained model, change this line:

pipe = StableDiffusionImg2ImgPipeline.from_pretrained("~/models/ghibli_model/")

Troubleshooting
Slow or Crashing? Try This:
✅ Reduce image size:

init_image = init_image.resize((256, 256))

✅ Lower AI influence:

strength = 0.5
guidance_scale = 5.0

✅ Check MPS is enabled:

python
import torch
print(torch.backends.mps.is_available())  # Should print True

---

Final Thoughts

Now you have your very own Studio Ghibli Art Generator running locally! With a bit of tweaking, you can generate stunning **anime-inspired landscapes and characters.

follow on github if you like this post:
[@Mahas1234](https://github.com/Mahas1234)