Spaces:
Runtime error
Runtime error
Jordan Legg
commited on
Commit
·
945b578
1
Parent(s):
13a0d1c
added upscaling
Browse files- app.py +37 -27
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -4,16 +4,20 @@ 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
|
| 13 |
MAX_IMAGE_SIZE = 2048
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
@spaces.GPU()
|
| 16 |
-
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
| 17 |
if randomize_seed:
|
| 18 |
seed = random.randint(0, MAX_SEED)
|
| 19 |
generator = torch.Generator().manual_seed(seed)
|
|
@@ -25,15 +29,22 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
|
|
| 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("""
|
|
@@ -46,32 +57,30 @@ with gr.Blocks() as demo:
|
|
| 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 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 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
|
|
@@ -79,11 +88,12 @@ with gr.Blocks() as demo:
|
|
| 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,
|
| 86 |
-
inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
|
| 87 |
outputs=[result, seed]
|
| 88 |
)
|
| 89 |
|
|
|
|
| 4 |
import random
|
| 5 |
import torch
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
+
from PIL import Image
|
| 8 |
+
from aura_sr import AuraSR
|
| 9 |
|
| 10 |
dtype = torch.bfloat16
|
| 11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
|
|
|
| 13 |
MAX_SEED = np.iinfo(np.int32).max
|
| 14 |
MAX_IMAGE_SIZE = 2048
|
| 15 |
|
| 16 |
+
# Initialize AuraSR model
|
| 17 |
+
aura_sr = AuraSR.from_pretrained("fal/AuraSR-v2")
|
| 18 |
+
|
| 19 |
@spaces.GPU()
|
| 20 |
+
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, upscale=False, progress=gr.Progress(track_tqdm=True)):
|
| 21 |
if randomize_seed:
|
| 22 |
seed = random.randint(0, MAX_SEED)
|
| 23 |
generator = torch.Generator().manual_seed(seed)
|
|
|
|
| 29 |
generator=generator,
|
| 30 |
guidance_scale=0.0
|
| 31 |
).images[0]
|
| 32 |
+
|
| 33 |
+
if upscale:
|
| 34 |
+
image = upscale_image(image)
|
| 35 |
+
|
| 36 |
return image, seed
|
| 37 |
|
| 38 |
+
@spaces.GPU()
|
| 39 |
+
def upscale_image(image):
|
| 40 |
+
return aura_sr.upscale_4x(image)
|
| 41 |
+
|
| 42 |
# Example prompt
|
| 43 |
example_prompt = "A vibrant red origami crane on a white background, intricate paper folds, studio lighting"
|
| 44 |
|
| 45 |
# Gradio interface
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
+
gr.Markdown("# FLUX.1 [schnell] Image Generator with AuraSR V2 Upscaling")
|
|
|
|
| 48 |
with gr.Row():
|
| 49 |
with gr.Column(scale=2):
|
| 50 |
gr.Markdown("""
|
|
|
|
| 57 |
- Uses advanced transformer architecture with flow matching techniques
|
| 58 |
- Capable of generating high-quality images in just a few inference steps
|
| 59 |
""")
|
|
|
|
| 60 |
with gr.Column(scale=3):
|
| 61 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your image description here...", value=example_prompt)
|
| 62 |
run_button = gr.Button("Generate")
|
| 63 |
result = gr.Image(label="Generated Image")
|
| 64 |
+
gr.Markdown("""
|
| 65 |
+
## Example Prompt
|
| 66 |
+
Try this example prompt or modify it to see how FLUX.1 [schnell] performs:
|
| 67 |
+
```
|
| 68 |
+
A vibrant red origami crane on a white background, intricate paper folds, studio lighting
|
| 69 |
+
```
|
| 70 |
+
""")
|
| 71 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 72 |
+
seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, label="Seed", randomize=True)
|
| 73 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 74 |
+
width = gr.Slider(minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, label="Width")
|
| 75 |
+
height = gr.Slider(minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, label="Height")
|
| 76 |
+
num_inference_steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, label="Number of inference steps")
|
| 77 |
+
upscale = gr.Checkbox(label="Upscale with AuraSR V2", value=False)
|
| 78 |
+
gr.Markdown("""
|
| 79 |
+
**Note:** FLUX.1 [schnell] is optimized for speed and can produce high-quality results with just a few inference steps.
|
| 80 |
+
Adjust the number of steps based on your speed/quality preference. More steps may improve quality but will increase generation time.
|
| 81 |
+
|
| 82 |
+
The upscaling option uses AuraSR V2 to increase the resolution of the generated image by 4x. This may significantly increase processing time.
|
| 83 |
+
""")
|
|
|
|
| 84 |
gr.Markdown("""
|
| 85 |
## Additional Information
|
| 86 |
- FLUX.1 [schnell] is based on a hybrid architecture of multimodal and parallel diffusion transformer blocks
|
|
|
|
| 88 |
- The model uses bfloat16 precision for efficient computation
|
| 89 |
- For optimal performance, running on a CUDA-enabled GPU is recommended
|
| 90 |
- For more details and other FLUX.1 variants, visit [Black Forest Labs](https://blackforestlabs.ai)
|
| 91 |
+
- The upscaling feature uses AuraSR V2, an open reproduction of the GigaGAN Upscaler from fal.ai
|
| 92 |
""")
|
| 93 |
|
| 94 |
run_button.click(
|
| 95 |
infer,
|
| 96 |
+
inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps, upscale],
|
| 97 |
outputs=[result, seed]
|
| 98 |
)
|
| 99 |
|
requirements.txt
CHANGED
|
@@ -5,6 +5,5 @@ torch
|
|
| 5 |
transformers==4.42.4
|
| 6 |
xformers
|
| 7 |
sentencepiece
|
| 8 |
-
|
| 9 |
-
torchvision
|
| 10 |
pillow
|
|
|
|
| 5 |
transformers==4.42.4
|
| 6 |
xformers
|
| 7 |
sentencepiece
|
| 8 |
+
aura-sr
|
|
|
|
| 9 |
pillow
|