TotoB12 commited on
Commit
a29d9b4
·
verified ·
1 Parent(s): 852188f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -1
app.py CHANGED
@@ -1,3 +1,108 @@
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.load("models/black-forest-labs/FLUX.1-schnell").launch()
 
1
+ # import gradio as gr
2
+
3
+ # gr.load("models/black-forest-labs/FLUX.1-schnell").launch()
4
+
5
  import gradio as gr
6
+ import numpy as np
7
+ import random
8
+ import spaces
9
+ import torch
10
+ from diffusers import DiffusionPipeline
11
+
12
+ from transformers import pipeline
13
+
14
+ pipe = pipeline(model="black-forest-labs/FLUX.1-schnell")
15
+
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)
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
+ with gr.Blocks(css=css) as demo:
31
+
32
+ with gr.Column(elem_id="col-container"):
33
+ gr.Markdown(f"""# FLUX.1 [schnell]
34
+ 12B param rectified flow transformer distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/) for 4 step generation
35
+ [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-schnell)]
36
+ """)
37
+
38
+ with gr.Row():
39
+
40
+ prompt = gr.Text(
41
+ label="Prompt",
42
+ show_label=False,
43
+ max_lines=1,
44
+ placeholder="Enter your prompt",
45
+ container=False,
46
+ )
47
+
48
+ run_button = gr.Button("Run", scale=0)
49
+
50
+ result = gr.Image(label="Result", show_label=False)
51
+
52
+ with gr.Accordion("Advanced Settings", open=False):
53
+
54
+ seed = gr.Slider(
55
+ label="Seed",
56
+ minimum=0,
57
+ maximum=MAX_SEED,
58
+ step=1,
59
+ value=0,
60
+ )
61
+
62
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
63
+
64
+ with gr.Row():
65
+
66
+ width = gr.Slider(
67
+ label="Width",
68
+ minimum=256,
69
+ maximum=MAX_IMAGE_SIZE,
70
+ step=32,
71
+ value=1024,
72
+ )
73
+
74
+ height = gr.Slider(
75
+ label="Height",
76
+ minimum=256,
77
+ maximum=MAX_IMAGE_SIZE,
78
+ step=32,
79
+ value=1024,
80
+ )
81
+
82
+ with gr.Row():
83
+
84
+
85
+ num_inference_steps = gr.Slider(
86
+ label="Number of inference steps",
87
+ minimum=1,
88
+ maximum=50,
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()