Tag Archives: LLM

Stable Diffusion WebUI

Stable Diffusion WebUI
Stable Diffusion WebUI Image Generator

We want to generate images locally. Several different applications can do this. To get started, we choose Stable Diffusion WebUI. This tool provides both text-image and image-image generation capabilities.

The WebUI part offers a user interface. Users can select image generation models, set up these models, and generate images from text.

Installing Stable Diffusion and the WebUI

A simple procedure for setting up this tool can be found here. We used the installation procedure for AUTOMATIC1111 on Apple Silicon. We created a simple shell script to launch the tool. Another good resource is the git repository for Stable Diffusion.

Bash
# Location where AI tools are installed
cd ~/AI/stable-diffusion-webui

# Log startup of Stable Diffusion
echo "*** Launching Stable Difussion at `date` ***" >> ~/AI/ai.log

# Run Stable Difussion using login/password; enable API
./webui.sh --api --listen --gradio-auth <uid>:<password> >> ~/AI/ai.log
Basg Script to Launch Stable Diffusion

We also used the Mac Automator to launch it when logging in.

The final step is to allow access to the WebUI via a proxy host, our Nginx Proxy Manager.

Choosing and Downloading Models

Once Stable Diffusion is installed, you’ll want to download models to generate images. A good source for models is Hugging Face. Here’s a guide to choosing models. We have these models installed here –

Learning To Use Stable Diffusion

The quality and look of the images you can generate using Stable Diffusion are endless. You can control how your images look and their content through the choices that you make in –

  • Your image prompt
  • The model you use
  • The settings you use to set up your model

You can find a beginner’s guide to Stable Diffusion here.

Generating Images Using Text LLMs

Using Open WebUI to Generate an Image (The button above the blue arrow triggers image-text)

The associated image generation engine can be used from Open WebUI to generate images from text created by LLMs. The steps to do this are as follows.

Configuring Open WebUI to Generate Images

First, you will need to set up Open WebUI image generation. Our current configuration is as follows:

Open WebUI Image Generation Set Up
  1. Use a text LLM like llava:34b to generate an Image Prompt describing the desired image.
  2. Select the generate image button (shown above the blue arrow in the image) to run your configured image generation model.
  • sd_xl_refiner1.0 – the base model used to generate images
  • Heun Sampler – A high-quality image convergence algorithm
  • CFG Scale is set to 7 – sets how closely the image prompt is followed during image generation.
  • Image Size is 800×600 – the size of the images in pixels.
  • Steps is set to 50, which is the number of steps used to refine the image based on your prompt.

You can experiment with these settings using the Stable Diffusion WebUI. This will help you find a combination that produces good results on your setup.

A Simple AI Project: Write Me A Story

Writing an AI Story

I wanted to do a simple project using our home lab’s LLMs and image generation tools. This project will show the capabilities of our platform. We will write an AI-generated story.

Creating The Story

I used the deep-seek-r1:32b LLM to create the AI story. Here’s the prompt –

Please write me a story about a lovely home by a lake in New England. The scene is a fall with colorful fall foliage.

The prompt is all the information I gave the LLM running here on my Mac Mini system. The AI model generated the rest. The model was run using a combination of Open WebUI and Ollama.

Creating The Accompanying Image


I used the gemma3:27b model to generate a photo prompt using the story, I then used the image generation choice in Open WebUI to generate an image from the image prompt. Here’s my setup for image generation in Open WebUI.

AI Story generated image

To generate the image, I used the AUTOMATIC1111 Stable Diffusion Engine along with the sd_xl_refiner_1.0 model. You can learn more about the local Stable Diffusion WebUI engine we are using.

The entire process was run locally on our Mac Mini system. It took less than 5 minutes to finish. How did my AI story turn out? You be the judge.

A Lovely Home by a Lake in New England

AI Story - accompanying AI generated image

In the heart of New England’s serene countryside stands an enchanting cottage, its wooden walls weathered yet warm, wrapped in ivy that clings gracefully like an embrace from the earth. The house is nestled beside a tranquil lake, whose surface mirrors the vibrant tapestry of autumn hues reflected by the surrounding foliage.

The exterior of the cottage is painted in soft earth tones—muted greens and rusty reds—that harmonize perfectly with the season’s palette. A wraparound porch invites weary travelers to rest, its wooden slats worn smooth by time and weather. The roof, steeply pitched, seems to bow under the weight of golden leaves that have drifted down from the trees.

The lake is a mirror of the fall, its waters rippling gently with hues of amber, burgundy, and gold. Along its shores, birches stand tall, their trunks white as snow against the deepening forest backdrop. The air carries the crispness of approaching winter, yet the sun still warms the land, casting long shadows that dance across the landscape.

Inside the cottage, a crackling fire in the hearth fills the room with a comforting glow. Plush chairs and sofas are arranged around the fireplace, their upholstery soft to the touch, inviting stories to be shared. Large windows frame the view of the lake and forest, allowing sunlight to filter through, highlighting dust motes that twirl in the golden beams.

The scent of wood smoke mingles with the earthy aroma of damp leaves outside. A cat curls up by the fire, its fur as warm as the blankets draped over the furniture. The house is alive with the sounds of life: the occasional splash from the lake, birdsong echoing through the trees, and the distant crunch of leaves underfoot as someone takes a stroll through the woods.

Autumn activities are a delightful part of daily life here. Apples picked from nearby orchards are transformed into pies that fill the house with a sweet aroma. Walks through the forest reveal hidden treasures—acorns, pine cones, and the occasional squirrel darting across the path. The simplicity of these moments is cherished, each day a gift to be savored.

As evening approaches, the sky softens into hues of peach and lavender, casting a warm glow over the landscape. The lake reflects this twilight beauty, its surface still as if holding its breath. Inside the cottage, the fire casts dancing shadows on the walls, and the sounds of the day give way to the gentle rustle of leaves in the breeze.

This is a place where time moves slowly, where each season brings its own magic. In the fall, the cottage by the lake becomes a haven of warmth and beauty, a testament to nature’s artistry, inviting all who enter to find peace and wonder in the simple joys of life.

Open WebUI

Open WebUI running llava:34b model
Open WebUI running an image analysis model.

Open WebUI simplifies the process of embedding AI capabilities into web environments. It allows developers to create dynamic interfaces. Users can enter data, view AI-generated outputs, and visualize real-time results. Its open-source nature provides flexibility for customization, adapting to various AI project requirements, or integrating with popular machine learning libraries. (This summary was written, in part, using the deepseek-r1:32b model).

Open WebUI Installation

We installed Open WebUI as a Docker container using the approach outlined in the video below.

Encryption and reverse proxy implementation is handled using Traefik. A docker-compose template file for our installation follows. It can be installed as a Portainer stack.

Dockerfile
services:
  openwebui:
    image: ghcr.io/open-webui/open-webui:0.5.20
    container_name: openwebui
    restart: unless-stopped
    
    environment:
      # Ollama Config
      - OLLAMA_BASE_URL=http://<your server IP>:11434

    # Map configuration to our docker persitent store
    volumes:
      - /mnt/nfs/docker/open-webui/data:/app/backend/data:rw
    
    # Connect to our Traefik proxy network
    networks:
      - proxy
    
    # Configure for Traefik reverse proxy
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.openwebui.rule=Host(`openwebui.anita-fred.net`)"
      - "traefik.http.middlewares.openwebui-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.openwebui.middlewares=openwebui-https-redirect"
      - "traefik.http.routers.openwebui-secure.entrypoints=https"
      - "traefik.http.routers.openwebui-secure.rule=Host(`openwebui.anita-fred.net`)"
      - "traefik.http.routers.openwebui-secure.tls=true"
      - "traefik.http.routers.openwebui-secure.service=openwebui"
      - "traefik.http.services.openwebui.loadbalancer.server.port=8080"
      - "traefik.docker.network=proxy"
      - "traefik.http.services.openwebui.loadBalancer.server.port=8080"

volumes:
  data:
    driver: local

networks:
  proxy:
    external: true
Docker Compose template for Open WebUI

Once the stack is running, you can set up your user account. The final step is to allow access to the WebUI via a proxy host, our Nginx Proxy Manager.

What Can I Do With Open WebUI and LLMs?

How to Tutorials

This tool can be used for a variety of applications involving local—and cloud-based LLMs. A great place to start is the Tutorials page.

Using Paid APIs

You can use Open WebUI with paid services like ChatGPT. The video above explains how to set this up.

Ollama: A Flexible Solution for Custom Machine Learning Models

Ollma image generated using AI

Ollama is an open-source platform designed for training and deploying custom machine-learning models locally. It enables users to work without relying on cloud services. It supports various model architectures, offering flexibility for diverse applications. Ideal for researchers and developers seeking privacy and control over their data, it facilitates offline AI development and experimentation. (This paragraph was written using the deepseek-r1:32b model running on an Apple Mac Mini M4 Pro).

We will use Ollama as a core tool to experiment with Large Language Models running locally on our LLM Workstation.

Installing and Running the Tool

You can install Ollama by downloading and running the installer. Next, you can choose a model (ex. llama3.2) and execute the following command to install and run it.

% ollama run llama3.2

We’ll ask the model to write a paragraph about large language models.

Ollama running the llama3.2 model

Commands to control the model process are entered by starting with a /. Here is a list of options.

Ollama commands

Exposing Ollama on Our Network

An API that enables applications to interact with or change the running model is available on http://localhost:11434. We want to make the API accessible across our network. We can create a plist to set the OLLAMA_HOST environment variable to “0.0.0.0:11434” to expose the API on our workstation’s IP interface. The list file should be created and saved in ~/Library/LaunchAgents. It is named com.ollama.plist. The plist’s contents are shown below.

XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.ollama</string>
    <key>Program</key>
    <string>/Applications/Ollama.app/Contents/MacOS/Ollama</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>OLLAMA_HOST</key>
        <string>0.0.0.0:11434</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>
Ollama com.ollama.plist contents

Finally, make sure that Ollama is stopped and run the following command. Then restart Ollama.

% launchctl load ~/Library/LaunchAgents/com.ollama.plist

You can now access the API anywhere on your network as http://<your workstation IP>:11434.

Building an LLM Workstation Using Apple Silicon

LLM Workstation using Apple Silicon

We are building a Large Language Model (LLM) workstation and server around a Mac Computer and Apple Silicon. My current machine is a Mac Mini M4 Pro. The specs for this machine are –

  • M4 Pro Chip
  • 48 GB of Unified Memory
  • 16 CPU Cores
  • 20 GPU Cores
  • 16-Core Neural Engine
  • 2 TB SSD Storage

We have a new Mac Studio M3 Ultra coming. This upgrade should give us considerably more processing power for my LLM Workstation. The specs for the new machine are –

  • M3 Ultra Chip
  • 512 GB of Unified Memory
  • 32 CPU Cores
  • 80 GPU Cores
  • 32-Core Neural Engine
  • 2 TB SSD Storage
  • 5 TB external Thunderbolt 5 SSD Storage

The setup has a pair of Apple 5K Studio Displays. They allow me to use it as my primary desktop machine.

Our LLM Workstation is a good platform for learning about Artificial Intelligence and Machine Learning. It is also suitable for learning about Machine learning and our planned AI projects.

We will set up our Workstation to run LLMs continuously. We will expose these LLMs via our Home Network. A web (Open WebUI) interface will connect them to other computers and smart devices around our home. Our current Docker setup will be used for this purpose.

Artificial Intelligence and Machine Learning

Artificial Intelligence

We are interested in learning about and experimenting with Artificial Intelligence and Machine Learning, and our plans include these projects.

  • Setting up an environment to run Large Language Models (LLMs) locally on a high-performance Mac system
  • Exposing our LLMs via a web interface so that we can use them within our network from multiple devices
  • Creating specialized versions of publicly available LLMs using Retrieval-Augmented Generation (RAG) and LLM Fine-Tuning techniques.
  • Running benchmarks using various LLMs on our Apple Silicon Workstation and Server.
  • Exploring Artificial Intelligence applications, including software generation, image generation, and domain-specific learning.

We are building a high-performance Workstation and Server using Apple Silicon. It should be ideal for these and many other projects.

Are you wondering what you can do with all of this? Here’s a simple project that we did using our AI platform.