Spaces:
Runtime error
Runtime error
Jordan Legg
commited on
Commit
Β·
e06d9b6
1
Parent(s):
51e970b
added more details
Browse files
app.py
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
-
import spaces
|
| 5 |
import torch
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
|
| 8 |
dtype = torch.bfloat16
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
-
|
| 11 |
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
| 12 |
|
| 13 |
MAX_SEED = np.iinfo(np.int32).max
|
|
@@ -19,30 +18,68 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
|
|
| 19 |
seed = random.randint(0, MAX_SEED)
|
| 20 |
generator = torch.Generator().manual_seed(seed)
|
| 21 |
image = pipe(
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
).images[0]
|
| 29 |
return image, seed
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
# Gradio interface
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
gr.Markdown("# FLUX.1 [schnell] Image Generator")
|
|
|
|
| 34 |
with gr.Row():
|
| 35 |
-
with gr.Column():
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
run_button = gr.Button("Generate")
|
| 38 |
-
with gr.Column():
|
| 39 |
result = gr.Image(label="Generated Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
with gr.Accordion("Advanced Settings", open=False):
|
| 41 |
seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, label="Seed", randomize=True)
|
| 42 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 43 |
width = gr.Slider(minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, label="Width")
|
| 44 |
height = gr.Slider(minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, label="Height")
|
| 45 |
num_inference_steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, label="Number of inference steps")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
run_button.click(
|
| 48 |
infer,
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import random
|
|
|
|
| 5 |
import torch
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
|
| 8 |
dtype = torch.bfloat16
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 10 |
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
| 11 |
|
| 12 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
| 18 |
seed = random.randint(0, MAX_SEED)
|
| 19 |
generator = torch.Generator().manual_seed(seed)
|
| 20 |
image = pipe(
|
| 21 |
+
prompt=prompt,
|
| 22 |
+
width=width,
|
| 23 |
+
height=height,
|
| 24 |
+
num_inference_steps=num_inference_steps,
|
| 25 |
+
generator=generator,
|
| 26 |
+
guidance_scale=0.0
|
| 27 |
+
).images[0]
|
| 28 |
return image, seed
|
| 29 |
|
| 30 |
+
# Example prompt
|
| 31 |
+
example_prompt = "A vibrant red origami crane on a white background, intricate paper folds, studio lighting"
|
| 32 |
+
|
| 33 |
# Gradio interface
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
gr.Markdown("# FLUX.1 [schnell] Image Generator")
|
| 36 |
+
|
| 37 |
with gr.Row():
|
| 38 |
+
with gr.Column(scale=2):
|
| 39 |
+
gr.Markdown("""
|
| 40 |
+
## About FLUX.1 [schnell]
|
| 41 |
+
- Fast text-to-image model optimized for local development and personal use
|
| 42 |
+
- Part of the FLUX.1 model family by Black Forest Labs
|
| 43 |
+
- Open-source: Available under Apache 2.0 license
|
| 44 |
+
- Supports resolutions between 0.1 and 2.0 megapixels
|
| 45 |
+
- Outperforms many larger models in quality and prompt adherence
|
| 46 |
+
- Uses advanced transformer architecture with flow matching techniques
|
| 47 |
+
- Capable of generating high-quality images in just a few inference steps
|
| 48 |
+
""")
|
| 49 |
+
|
| 50 |
+
with gr.Column(scale=3):
|
| 51 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Enter your image description here...", value=example_prompt)
|
| 52 |
run_button = gr.Button("Generate")
|
|
|
|
| 53 |
result = gr.Image(label="Generated Image")
|
| 54 |
+
|
| 55 |
+
gr.Markdown("""
|
| 56 |
+
## Example Prompt
|
| 57 |
+
Try this example prompt or modify it to see how FLUX.1 [schnell] performs:
|
| 58 |
+
```
|
| 59 |
+
A vibrant red origami crane on a white background, intricate paper folds, studio lighting
|
| 60 |
+
```
|
| 61 |
+
""")
|
| 62 |
+
|
| 63 |
with gr.Accordion("Advanced Settings", open=False):
|
| 64 |
seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, label="Seed", randomize=True)
|
| 65 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 66 |
width = gr.Slider(minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, label="Width")
|
| 67 |
height = gr.Slider(minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, label="Height")
|
| 68 |
num_inference_steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, label="Number of inference steps")
|
| 69 |
+
|
| 70 |
+
gr.Markdown("""
|
| 71 |
+
**Note:** FLUX.1 [schnell] is optimized for speed and can produce high-quality results with just a few inference steps.
|
| 72 |
+
Adjust the number of steps based on your speed/quality preference. More steps may improve quality but will increase generation time.
|
| 73 |
+
""")
|
| 74 |
+
|
| 75 |
+
gr.Markdown("""
|
| 76 |
+
## Additional Information
|
| 77 |
+
- FLUX.1 [schnell] is based on a hybrid architecture of multimodal and parallel diffusion transformer blocks
|
| 78 |
+
- It supports various aspect ratios within the 0.1 to 2.0 megapixel range
|
| 79 |
+
- The model uses bfloat16 precision for efficient computation
|
| 80 |
+
- For optimal performance, running on a CUDA-enabled GPU is recommended
|
| 81 |
+
- For more details and other FLUX.1 variants, visit [Black Forest Labs](https://blackforestlabs.ai)
|
| 82 |
+
""")
|
| 83 |
|
| 84 |
run_button.click(
|
| 85 |
infer,
|