mirror of
https://github.com/pinokiofactory/flux-webui.git
synced 2024-10-05 23:57:57 +03:00
update
This commit is contained in:
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Flux WebUI
|
||||
|
||||
Minimal Flux Web UI powered by Gradio & Diffusers.
|
||||
|
||||
# Install
|
||||
|
||||
## 1. One click install
|
||||
|
||||
The easiest way is to use https://pinokio.computer
|
||||
|
||||
## 2. Install manually
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
# Run
|
||||
|
||||
```
|
||||
python app.py
|
||||
```
|
||||
96
app.py
96
app.py
@@ -1,20 +1,39 @@
|
||||
# schnell
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
import random
|
||||
import torch
|
||||
from diffusers import DiffusionPipeline
|
||||
from diffusers import FluxPipeline, FlowMatchEulerDiscreteScheduler, FluxTransformer2DModel
|
||||
import devicetorch
|
||||
|
||||
dtype = torch.bfloat16
|
||||
device = devicetorch.get(torch)
|
||||
|
||||
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
||||
|
||||
MAX_SEED = np.iinfo(np.int32).max
|
||||
MAX_IMAGE_SIZE = 2048
|
||||
selected = None
|
||||
css="""
|
||||
nav {
|
||||
text-align: center;
|
||||
}
|
||||
#logo{
|
||||
width: 50px;
|
||||
display: inline;
|
||||
}
|
||||
"""
|
||||
def infer(prompt, checkpoint="black-fores-labs/FLUX.1-schnell", seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
||||
global pipe
|
||||
global selected
|
||||
# if the new checkpoint is different from the selected one, re-instantiate the pipe
|
||||
if selected != checkpoint:
|
||||
if checkpoint == "sayakpaul/FLUX.1-merged":
|
||||
transformer = FluxTransformer2DModel.from_pretrained("sayakpaul/FLUX.1-merged", torch_dtype=dtype)
|
||||
pipe = FluxPipeline.from_pretrained("cocktailpeanut/xulf-d", transformer=transformer, torch_dtype=torch.bfloat16)
|
||||
else:
|
||||
pipe = FluxPipeline.from_pretrained(checkpoint, torch_dtype=torch.bfloat16)
|
||||
|
||||
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
||||
#pipe.enable_model_cpu_offload()
|
||||
pipe.to(device)
|
||||
pipe.enable_attention_slicing()
|
||||
selected = checkpoint
|
||||
devicetorch.empty_cache(torch)
|
||||
if randomize_seed:
|
||||
seed = random.randint(0, MAX_SEED)
|
||||
generator = torch.Generator().manual_seed(seed)
|
||||
@@ -27,30 +46,15 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
|
||||
guidance_scale=0.0
|
||||
).images[0]
|
||||
return image, seed
|
||||
|
||||
examples = [
|
||||
"a tiny astronaut hatching from an egg on the moon",
|
||||
"a cat holding a sign that says hello world",
|
||||
"an anime illustration of a wiener schnitzel",
|
||||
]
|
||||
|
||||
css="""
|
||||
#col-container {
|
||||
margin: 0 auto;
|
||||
max-width: 520px;
|
||||
}
|
||||
"""
|
||||
|
||||
def update_slider(checkpoint, num_inference_steps):
|
||||
if checkpoint == "sayakpaul/FLUX.1-merged":
|
||||
return 8
|
||||
else:
|
||||
return 4
|
||||
with gr.Blocks(css=css) as demo:
|
||||
|
||||
with gr.Column(elem_id="col-container"):
|
||||
gr.Markdown(f"""# FLUX.1 [schnell]
|
||||
12B param rectified flow transformer distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/) for 4 step generation
|
||||
[[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-schnell)]
|
||||
""")
|
||||
|
||||
gr.HTML("<nav><img id='logo' src='file/icon.webp'/></nav>")
|
||||
with gr.Row():
|
||||
|
||||
prompt = gr.Text(
|
||||
label="Prompt",
|
||||
show_label=False,
|
||||
@@ -58,13 +62,16 @@ with gr.Blocks(css=css) as demo:
|
||||
placeholder="Enter your prompt",
|
||||
container=False,
|
||||
)
|
||||
|
||||
run_button = gr.Button("Run", scale=0)
|
||||
|
||||
result = gr.Image(label="Result", show_label=False)
|
||||
|
||||
with gr.Accordion("Advanced Settings", open=False):
|
||||
|
||||
with gr.Accordion("Advanced Settings"):
|
||||
checkpoint = gr.Dropdown(
|
||||
value= "black-forest-labs/FLUX.1-schnell",
|
||||
choices=[
|
||||
"black-forest-labs/FLUX.1-schnell",
|
||||
"sayakpaul/FLUX.1-merged"
|
||||
]
|
||||
)
|
||||
seed = gr.Slider(
|
||||
label="Seed",
|
||||
minimum=0,
|
||||
@@ -72,11 +79,8 @@ with gr.Blocks(css=css) as demo:
|
||||
step=1,
|
||||
value=0,
|
||||
)
|
||||
|
||||
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
||||
|
||||
with gr.Row():
|
||||
|
||||
width = gr.Slider(
|
||||
label="Width",
|
||||
minimum=256,
|
||||
@@ -84,18 +88,14 @@ with gr.Blocks(css=css) as demo:
|
||||
step=32,
|
||||
value=1024,
|
||||
)
|
||||
|
||||
height = gr.Slider(
|
||||
label="Height",
|
||||
minimum=256,
|
||||
maximum=MAX_IMAGE_SIZE,
|
||||
step=32,
|
||||
value=1024,
|
||||
value=576,
|
||||
)
|
||||
|
||||
with gr.Row():
|
||||
|
||||
|
||||
num_inference_steps = gr.Slider(
|
||||
label="Number of inference steps",
|
||||
minimum=1,
|
||||
@@ -103,21 +103,11 @@ with gr.Blocks(css=css) as demo:
|
||||
step=1,
|
||||
value=4,
|
||||
)
|
||||
|
||||
gr.Examples(
|
||||
examples = examples,
|
||||
fn = infer,
|
||||
inputs = [prompt],
|
||||
outputs = [result, seed],
|
||||
cache_examples="lazy"
|
||||
)
|
||||
|
||||
checkpoint.change(fn=update_slider, inputs=[checkpoint], outputs=[num_inference_steps])
|
||||
gr.on(
|
||||
triggers=[run_button.click, prompt.submit],
|
||||
fn = infer,
|
||||
inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
|
||||
inputs = [prompt, checkpoint, seed, randomize_seed, width, height, num_inference_steps],
|
||||
outputs = [result, seed]
|
||||
)
|
||||
|
||||
demo.launch()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module.exports = {
|
||||
uri: "torch.js",
|
||||
params: {
|
||||
venv: "env", // Edit this to customize the venv folder path
|
||||
// xformers: true // uncomment this line if your project requires xformers
|
||||
xformers: true // uncomment this line if your project requires xformers
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const path = require('path')
|
||||
module.exports = {
|
||||
version: "2.0",
|
||||
title: "flux-all",
|
||||
description: "",
|
||||
title: "flux-webui",
|
||||
description: "Minimal Flux Web UI powered by Gradio & Diffusers",
|
||||
icon: "icon.webp",
|
||||
menu: async (kernel, info) => {
|
||||
let installed = info.exists("env")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
gradio
|
||||
devicetorch
|
||||
accelerate
|
||||
git+https://github.com/huggingface/diffusers.git@flux-pipeline
|
||||
torch
|
||||
git+https://github.com/peanutcocktail/diffusers.git
|
||||
transformers==4.42.4
|
||||
xformers
|
||||
sentencepiece
|
||||
protobuf
|
||||
einops
|
||||
|
||||
Reference in New Issue
Block a user