abhillubillu commited on
Commit
4882b86
1 Parent(s): 8eebfa4

Upload 4 files

Browse files
Files changed (4) hide show
  1. README (2).md +13 -0
  2. app (3).py +122 -0
  3. gitattributes (3) +35 -0
  4. requirements (4).txt +7 -0
README (2).md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: FLUX.1 [Schnell]
3
+ emoji: 🏎️💨
4
+ colorFrom: yellow
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 4.40.0
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 (3).py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 tiny astronaut hatching from an egg on the moon",
33
+ "a cat holding a sign that says hello world",
34
+ "an anime illustration of a wiener schnitzel",
35
+ ]
36
+
37
+ css="""
38
+ #col-container {
39
+ margin: 0 auto;
40
+ max-width: 520px;
41
+ }
42
+ """
43
+
44
+ with gr.Blocks(css=css) as demo:
45
+
46
+ with gr.Column(elem_id="col-container"):
47
+ gr.Markdown(f"""# FLUX.1 [schnell]
48
+ 12B param rectified flow transformer distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/) for 4 step generation
49
+ [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-schnell)]
50
+ """)
51
+
52
+ with gr.Row():
53
+
54
+ prompt = gr.Text(
55
+ label="Prompt",
56
+ show_label=False,
57
+ max_lines=1,
58
+ placeholder="Enter your prompt",
59
+ container=False,
60
+ )
61
+
62
+ run_button = gr.Button("Run", scale=0)
63
+
64
+ result = gr.Image(label="Result", show_label=False)
65
+
66
+ with gr.Accordion("Advanced Settings", open=False):
67
+
68
+ seed = gr.Slider(
69
+ label="Seed",
70
+ minimum=0,
71
+ maximum=MAX_SEED,
72
+ step=1,
73
+ value=0,
74
+ )
75
+
76
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
77
+
78
+ with gr.Row():
79
+
80
+ width = gr.Slider(
81
+ label="Width",
82
+ minimum=256,
83
+ maximum=MAX_IMAGE_SIZE,
84
+ step=32,
85
+ value=1024,
86
+ )
87
+
88
+ height = gr.Slider(
89
+ label="Height",
90
+ minimum=256,
91
+ maximum=MAX_IMAGE_SIZE,
92
+ step=32,
93
+ value=1024,
94
+ )
95
+
96
+ with gr.Row():
97
+
98
+
99
+ num_inference_steps = gr.Slider(
100
+ label="Number of inference steps",
101
+ minimum=1,
102
+ maximum=50,
103
+ step=1,
104
+ value=4,
105
+ )
106
+
107
+ gr.Examples(
108
+ examples = examples,
109
+ fn = infer,
110
+ inputs = [prompt],
111
+ outputs = [result, seed],
112
+ cache_examples="lazy"
113
+ )
114
+
115
+ gr.on(
116
+ triggers=[run_button.click, prompt.submit],
117
+ fn = infer,
118
+ inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
119
+ outputs = [result, seed]
120
+ )
121
+
122
+ demo.launch()
gitattributes (3) ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
requirements (4).txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ accelerate
2
+ git+https://github.com/huggingface/diffusers.git
3
+ invisible_watermark
4
+ torch
5
+ transformers==4.42.4
6
+ xformers
7
+ sentencepiece