Tag Archives: AI

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.

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.