nexus-dev commited on
Commit
febc836
·
1 Parent(s): 7dc1bc1

Deploy FLUX.1 Schnell image generator

Browse files
Files changed (3) hide show
  1. README.md +6 -6
  2. app.py +108 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
- title: CogVideo5b
3
- emoji: 👀
4
- colorFrom: red
5
- colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 6.29.1
8
- python_version: '3.12'
9
  app_file: app.py
10
  pinned: false
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: FLUX.1 Schnell Generator
3
+ emoji: 🚀
4
+ colorFrom: yellow
5
+ colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 5.43.1
 
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
14
+ MAX_IMAGE_SIZE = 2048
15
+
16
+ @spaces.GPU()
17
+ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
18
+ if randomize_seed:
19
+ seed = random.randint(0, MAX_SEED)
20
+ generator = torch.Generator().manual_seed(seed)
21
+ image = pipe(
22
+ prompt = prompt,
23
+ width = width,
24
+ height = height,
25
+ num_inference_steps = num_inference_steps,
26
+ generator = generator,
27
+ guidance_scale=0.0
28
+ ).images[0]
29
+ return image, seed
30
+
31
+ examples = [
32
+ "a cartoon character exploring a futuristic neon city",
33
+ "a cute cat astronaut floating in colorful space",
34
+ ]
35
+
36
+ css="""
37
+ #col-container {
38
+ margin: 0 auto;
39
+ max-width: 520px;
40
+ }
41
+ """
42
+
43
+ with gr.Blocks(css=css) as demo:
44
+ with gr.Column(elem_id="col-container"):
45
+ gr.Markdown("# FLUX.1 [schnell] Generator\nUltra-fast 4-step distilled image generation.")
46
+
47
+ with gr.Row():
48
+ prompt = gr.Text(
49
+ label="Prompt",
50
+ show_label=False,
51
+ max_lines=1,
52
+ placeholder="Enter your prompt",
53
+ container=False,
54
+ )
55
+ run_button = gr.Button("Generate", scale=0)
56
+
57
+ result = gr.Image(label="Result", show_label=False)
58
+
59
+ with gr.Accordion("Advanced Settings", open=False):
60
+ seed = gr.Slider(
61
+ label="Seed",
62
+ minimum=0,
63
+ maximum=MAX_SEED,
64
+ step=1,
65
+ value=0,
66
+ )
67
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
68
+
69
+ with gr.Row():
70
+ width = gr.Slider(
71
+ label="Width",
72
+ minimum=256,
73
+ maximum=MAX_IMAGE_SIZE,
74
+ step=32,
75
+ value=704,
76
+ )
77
+ height = gr.Slider(
78
+ label="Height",
79
+ minimum=256,
80
+ maximum=MAX_IMAGE_SIZE,
81
+ step=32,
82
+ value=1280,
83
+ )
84
+
85
+ num_inference_steps = gr.Slider(
86
+ label="Inference Steps",
87
+ minimum=1,
88
+ maximum=12,
89
+ step=1,
90
+ value=4,
91
+ )
92
+
93
+ gr.Examples(
94
+ examples = examples,
95
+ fn = infer,
96
+ inputs = [prompt],
97
+ outputs = [result, seed],
98
+ cache_examples="lazy"
99
+ )
100
+
101
+ gr.on(
102
+ triggers=[run_button.click, prompt.submit],
103
+ fn = infer,
104
+ inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
105
+ outputs = [result, seed]
106
+ )
107
+
108
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ accelerate
2
+ diffusers==0.38.0
3
+ invisible_watermark
4
+ torch
5
+ transformers==4.57.6
6
+ xformers
7
+ sentencepiece