Thursday, September 5, 2024

(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

FLUX, an advanced AI image generator, has catapulted to the forefront of the artificial intelligence scene. It's renowned for its capacity to create intricately detailed and imaginative images from text prompts, making it a favored resource for artists, designers, and AI aficionados. Although web-accessible versions are offered, running FLUX on your personal computer has benefits including quicker processing, unrestricted usage, and superior privacy. This guide will provide instructions on how to run FLUX locally on Windows, Mac, and Linux systems.Load More

Before we get started, Let’s talk about the Best FlowGPT Image Generator Alternative that gives you much better quality.

The following Images are generated with Anakin AI’s AI Image Generator, Try it out now! 👇👇👇

FLUX AI Image Generator | Anakin
Better than Midjourney and Stable Diffusion, Try the Open Source, State-of-the-art image generation Tool: FLUX Pro Online!
(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux
Anakin.ai - One-Stop AI App Platform
Generate Content, Images, Videos, and Voice; Craft Automated Workflows, Custom AI Apps, and Intelligent Agents. Your exclusive AI app customization workstation.
(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux
(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

Prompt: innocent and alluring, long hair, alternative vibe, beautiful eyes, freckles, medium breasts, subtle cleavage, tight body, slutty, candid picture, (cozy bedroom), off-shoulder shirt, dynamic angle, vibrant lighting, high contrast, dramatic shadows, highly detailed, detailed skin, depth of field, film grain

(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

Prompt: pov photo of model seated at restaurant table across from camera, in romantic upscale setting facing camera. medium rare steak is on the table sliced into several pieces, on a wooden board, which also has a small dish of what appears to be a side condiment or salsa with chopped vegetables.

(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

Prompt: A TV show poster for “Breaking Bread,” a parody of Breaking Bad. A stern baker in a flour-dusted apron holds a rolling pin like a weapon in a rustic bakery. Bread loaves and flour bags mimic the desert backdrop. The chalkboard menu lists pun-filled items. The title uses a gritty font for “Breaking” and golden, bread-like letters for “Bread.” Tagline: “Baking is a Dangerous Game.”

(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

Prompt: lovely Japanese Anime Style, an adult woman with white angel wings, black devil horns and a black headband, red halo, long pink wavy hair, brown eyes, evil smirk. Wearing black and white techwear hoodie, jeans, with lots of straps and buckles. She holding a spray-paint can and is standing against a wall with the text “Anakin AI Image Generator” in large black and yellow spray-paint graffiti beside her.

These awesome, high quality Images are generated with Anakin AI’s AI Image Generator, Try it out now! 👇👇👇

Anakin.ai - One-Stop AI App Platform

Generate Content, Images, Videos, and Voice; Craft Automated Workflows, Custom AI Apps, and Intelligent Agents. Your…

app.anakin.ai

Method 1: Using ComfyUI to Run FLUX Locally

ComfyUI is a powerful and user-friendly interface for running AI models, including FLUX. This method is recommended for users who prefer a graphical interface and don’t want to deal with command-line operations.

Step 1: Install ComfyUI

  1. Visit the ComfyUI GitHub releases page: https://github.com/comfyanonymous/ComfyUI/releases
  2. Download the latest version for your operating system.
  3. Extract the downloaded archive to a location of your choice.
(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

Step 2: Download FLUX Models

  1. Visit the FLUX HuggingFace repository: https://huggingface.co/black-forest-labs/FLUX.1-schnell/tree/main
  2. Download the following files:
  • flux_schnell.safetensors (main model)
  • ae.safetensors (VAE file)

3. From the FLUX text encoders repository (https://huggingface.co/comfyanonymous/flux_text_encoders/tree/main), download:

  • t5xxl_fp16.safetensors (for systems with 32GB+ RAM)
  • t5xxl_fp8_e4m3fn.safetensors (for systems with less than 32GB RAM)
  • clip_l.safetensors

Step 3: Place Files in ComfyUI Folders

  1. Move flux_schnell.safetensors to ComfyUI/models/checkpoints/
  2. Move ae.safetensors to ComfyUI/models/vae/
  3. Move t5xxl_fp16.safetensors (or t5xxl_fp8_e4m3fn.safetensors) and clip_l.safetensors to ComfyUI/models/clip/

Step 4: Run ComfyUI

  1. Open a terminal or command prompt.
  2. Navigate to the ComfyUI folder.
  3. Run the appropriate command for your system:
  • Windows: python_embeded\\\\python.exe -m ComfyUI
  • Mac/Linux: python3 main.py

4. Open a web browser and go to http://localhost:8188

Step 5: Set Up FLUX Workflow

  1. In the ComfyUI interface, right-click and add the following nodes:
  • CLIP Text Encode (T5XXL)
  • CLIP Text Encode (CLIP L)
  • Flux Guidance
  • Empty Latent Image
  • VAE Decode

2. Connect the nodes as follows:

  • CLIP Text Encode (T5XXL) output to Flux Guidance “t5_emb” input
  • CLIP Text Encode (CLIP L) output to Flux Guidance “clip_emb” input
  • Empty Latent Image output to Flux Guidance “latent” input
  • Flux Guidance output to VAE Decode input

3. Set your desired parameters in each node.

Step 6: Generate Images

  1. Enter your text prompt in both CLIP Text Encode nodes.
  2. Click “Queue Prompt” to generate an image.

Method 2: Using Stable Diffusion WebUI

Stable Diffusion WebUI is another popular interface for running AI models, including FLUX. This method is suitable for users who are already familiar with Stable Diffusion and prefer its interface.

Step 1: Install Stable Diffusion WebUI

  1. Clone the Stable Diffusion WebUI repository:

git clone <https://github.com/AUTOMATIC1111/stable-diffusion-webui.git>

2. Navigate to the cloned directory:

cd stable-diffusion-webui

3. Run the appropriate script for your system:

  • Windows: webui-user.bat
  • Mac/Linux: ./webui.sh

Step 2: Download FLUX Models

Follow the same steps as in Method 1 to download the FLUX models and VAE file.

Step 3: Place Files in Stable Diffusion WebUI Folders

  1. Move flux_schnell.safetensors to stable-diffusion-webui/models/Stable-diffusion/
  2. Move ae.safetensors to stable-diffusion-webui/models/VAE/

Step 4: Configure Stable Diffusion WebUI

  1. In the WebUI, go to the “Settings” tab.
  2. Under “Stable Diffusion,” select the FLUX model.
  3. Under “VAE,” select the FLUX VAE file.
  4. Click “Apply settings” and restart the WebUI.

Step 5: Generate Images

  1. In the text-to-image tab, enter your prompt.
  2. Adjust settings as desired.
  3. Click “Generate” to create your image.
(4 Methods) How to Run FLUX Locally on Windows, Mac, and Linux

Method 3: Using Stability Matrix

Stability Matrix is a powerful, user-friendly application that allows you to run various AI models, including FLUX, with a sleek interface and advanced features. This method is ideal for users who want a balance between ease of use and customization options.

Step 1: Install Stability Matrix

  1. Visit the Stability Matrix GitHub page: https://github.com/LykosAI/StabilityMatrix
  2. Download the latest release for your operating system (Windows, Mac, or Linux).
  3. Install the application following the instructions for your OS:
  • Windows: Run the installer executable.
  • Mac: Drag the .app file to your Applications folder.
  • Linux: Extract the AppImage and make it executable.

Step 2: Set Up Stability Matrix

  1. Launch Stability Matrix.
  2. During the first run, the application will guide you through the initial setup.
  3. Choose your preferred installation location and GPU settings.

Step 3: Install ComfyUI Package

  1. In Stability Matrix, go to the “Package Manager” tab.
  2. Find “ComfyUI” in the list of available packages.
  3. Click “Install” next to ComfyUI.
  4. Wait for the installation to complete.

Step 4: Download FLUX Models

  1. In Stability Matrix, go to the “Model Manager” tab.
  2. Click “Add New Model.”
  3. In the search bar, type “FLUX” and press Enter.
  4. Find the following models and click “Download” for each:
  • FLUX.1-schnell (main model)
  • FLUX VAE (VAE file)
  • FLUX T5XXL Text Encoder (choose fp16 or fp8 based on your system’s RAM)
  • FLUX CLIP L Text Encoder

Step 5: Configure ComfyUI for FLUX

  1. In Stability Matrix, go to the “Installed Packages” tab.
  2. Find ComfyUI and click “Launch.”
  3. When ComfyUI opens in your browser, right-click in the workspace and add the following nodes:
  • CLIP Text Encode (T5XXL)
  • CLIP Text Encode (CLIP L)
  • Flux Guidance
  • Empty Latent Image
  • VAE Decode

Step 6: Set Up FLUX Workflow

  1. Connect the nodes as follows:
  • CLIP Text Encode (T5XXL) output to Flux Guidance “t5_emb” input
  • CLIP Text Encode (CLIP L) output to Flux Guidance “clip_emb” input
  • Empty Latent Image output to Flux Guidance “latent” input
  • Flux Guidance output to VAE Decode input

2. In each node, select the appropriate FLUX model:

  • For CLIP Text Encode (T5XXL), choose the FLUX T5XXL Text Encoder
  • For CLIP Text Encode (CLIP L), choose the FLUX CLIP L Text Encoder
  • For Flux Guidance, choose FLUX.1-schnell
  • For VAE Decode, choose FLUX VAE

Step 7: Generate Images

  1. Enter your desired text prompt in both CLIP Text Encode nodes.
  2. Adjust parameters in the Flux Guidance node:
  • Set the number of steps (e.g., 20–50)
  • Adjust the guidance scale (e.g., 7–9)
  • Set the desired width and height (e.g., 512x512)

3. Click “Queue Prompt” to generate an image.

Method 4: Using Python Script (Advanced)

This method is for advanced users who are comfortable with Python and prefer a more customizable approach.

Step 1: Set Up Python Environment

  1. Install Python 3.8 or higher.

2. Create a new virtual environment:

python -m venv flux_env

3. Activate the virtual environment:

  • Windows: flux_env\\\\Scripts\\\\activate
  • Mac/Linux: source flux_env/bin/activate

Step 2: Install Dependencies

  1. Install PyTorch with CUDA support (visit pytorch.org for the correct command for your system).

2. Install other required packages:

pip install transformers diffusers accelerate

Step 3: Download FLUX Models

Follow the same steps as in Method 1 to download the FLUX models and VAE file.

Step 4: Create Python Script

Create a new file named run_flux.py with the following content:

import torch

from diffusers import FluxModel, FluxScheduler, FluxPipeline

from transformers import T5EncoderModel, CLIPTextModel, CLIPTokenizer

def load_flux():

flux_model = FluxModel.from_pretrained(“path/to/flux_schnell.safetensors”)

t5_model = T5EncoderModel.from_pretrained(“path/to/t5xxl_fp16.safetensors”)

clip_model = CLIPTextModel.from_pretrained(“path/to/clip_l.safetensors”)

clip_tokenizer = CLIPTokenizer.from_pretrained(“openai/clip-vit-large-patch14”)

scheduler = FluxScheduler()

pipeline = FluxPipeline(

flux_model=flux_model,

t5_model=t5_model,

clip_model=clip_model,

clip_tokenizer=clip_tokenizer,

scheduler=scheduler

)

return pipeline

def generate_image(pipeline, prompt, num_inference_steps=50):

image = pipeline(prompt, num_inference_steps=num_inference_steps).images[0]

return image

if __name__ == “__main__”:

pipeline = load_flux()

prompt = “A beautiful landscape with mountains and a lake”

image = generate_image(pipeline, prompt)

image.save(“flux_generated_image.png”)

Step 5: Run the Script

  1. Open a terminal or command prompt.
  2. Activate your virtual environment.
  3. Run the script:

python run_flux.py

Conclusion

Using FLUX locally introduces you to a realm of endless possibilities in AI-generated art and design. Whether through the user-friendly ComfyUI, the familiar Stable Diffusion WebUI, or a custom Python script, you can now control FLUX's power on your local machine. Always adhere to the model’s licensing terms and use it responsibly.

Explore FLUX in-depth, play around with different prompts, settings, and workflows to appreciated its full potential. Running FLUX locally not only offers more control during generation, but allows quicker iterations and deeper comprehension of the model's abilities.

With dedication and imagination, you're on your way to producing extraordinary, superior-grade visuals that stretch the limits of AI-aided art. Relish your excursion into the intriguing picture of FLUX and AI image generation! Be the Elon Musk of your own creations!



from Anakin Blog http://anakin.ai/blog/how-to-run-flux-locally-onwindows-mac-and-linux/
via IFTTT

No comments:

Post a Comment

Gemini-Exp-1114 Is Here: #1 LLM Model Right Now?

Google’s experimental AI model, Gemini-Exp-1114 , is making waves in the AI community with its exceptional performance across diverse domai...