beoswindvip commited on
Commit
e396cda
β€’
1 Parent(s): 7f42986

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +6 -6
  2. app.py +128 -0
  3. gitattributes +35 -0
  4. requirements.txt +6 -0
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
- title: Bikini
3
- emoji: 🐨
4
- colorFrom: pink
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
- license: gfdl
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: FLUX.1 [merged]
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.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ import spaces
5
+ import torch
6
+ from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, FluxTransformer2DModel
7
+ from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
8
+
9
+ dtype = torch.bfloat16
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+
12
+ pipe = DiffusionPipeline.from_pretrained("sayakpaul/FLUX.1-merged", torch_dtype=dtype).to(device)
13
+
14
+ MAX_SEED = np.iinfo(np.int32).max
15
+ MAX_IMAGE_SIZE = 2048
16
+
17
+ @spaces.GPU()
18
+ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=8, progress=gr.Progress(track_tqdm=True)):
19
+ if randomize_seed:
20
+ seed = random.randint(0, MAX_SEED)
21
+ generator = torch.Generator().manual_seed(seed)
22
+ image = pipe(
23
+ prompt = prompt,
24
+ width = width,
25
+ height = height,
26
+ num_inference_steps = num_inference_steps,
27
+ generator = generator,
28
+ guidance_scale=guidance_scale
29
+ ).images[0]
30
+ return image, seed
31
+
32
+ examples = [
33
+ "a tiny astronaut hatching from an egg on the moon",
34
+ "a cat holding a sign that says hello world",
35
+ "an anime illustration of a wiener schnitzel",
36
+ ]
37
+
38
+ css="""
39
+ #col-container {
40
+ margin: 0 auto;
41
+ max-width: 520px;
42
+ }
43
+ """
44
+
45
+ with gr.Blocks(css=css) as demo:
46
+
47
+ with gr.Column(elem_id="col-container"):
48
+ gr.Markdown(f"""# [FLUX.1 [merged]](https://huggingface.co/sayakpaul/FLUX.1-merged)
49
+ Merge by [Sayak Paul](https://huggingface.co/sayakpaul) of 2 of the 12B param rectified flow transformers [FLUX.1 [dev]](https://huggingface.co/black-forest-labs/FLUX.1-dev) and [FLUX.1 [schnell]](https://huggingface.co/black-forest-labs/FLUX.1-schnell) by [Black Forest Labs](https://blackforestlabs.ai/)
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
+ run_button = gr.Button("Run", scale=0)
62
+
63
+ num_inference_steps = gr.Slider(
64
+ label="Number of inference steps",
65
+ minimum=1,
66
+ maximum=50,
67
+ step=1,
68
+ value=8,
69
+ )
70
+
71
+ result = gr.Image(label="Result", show_label=False)
72
+
73
+ with gr.Accordion("Advanced Settings", open=False):
74
+
75
+ seed = gr.Slider(
76
+ label="Seed",
77
+ minimum=0,
78
+ maximum=MAX_SEED,
79
+ step=1,
80
+ value=0,
81
+ )
82
+
83
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
84
+
85
+ with gr.Row():
86
+
87
+ width = gr.Slider(
88
+ label="Width",
89
+ minimum=256,
90
+ maximum=MAX_IMAGE_SIZE,
91
+ step=32,
92
+ value=1024,
93
+ )
94
+
95
+ height = gr.Slider(
96
+ label="Height",
97
+ minimum=256,
98
+ maximum=MAX_IMAGE_SIZE,
99
+ step=32,
100
+ value=1024,
101
+ )
102
+
103
+ with gr.Row():
104
+
105
+ guidance_scale = gr.Slider(
106
+ label="Guidance Scale",
107
+ minimum=1,
108
+ maximum=15,
109
+ step=0.1,
110
+ value=3.5,
111
+ )
112
+
113
+ gr.Examples(
114
+ examples = examples,
115
+ fn = infer,
116
+ inputs = [prompt],
117
+ outputs = [result, seed],
118
+ cache_examples="lazy"
119
+ )
120
+
121
+ gr.on(
122
+ triggers=[run_button.click, prompt.submit],
123
+ fn = infer,
124
+ inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
125
+ outputs = [result, seed]
126
+ )
127
+
128
+ demo.launch()
gitattributes 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.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ accelerate
2
+ git+https://github.com/huggingface/diffusers.git
3
+ torch
4
+ transformers==4.42.4
5
+ xformers
6
+ sentencepiece