davidberenstein1957 HF staff commited on
Commit
48dd920
1 Parent(s): 86f96a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -88
app.py CHANGED
@@ -1,8 +1,10 @@
 
 
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
@@ -19,104 +21,53 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
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()
 
1
+ import random
2
+
3
  import gradio as gr
4
  import numpy as np
 
5
  import spaces
6
  import torch
7
+ from dataset_viber import CollectorInterface
8
  from diffusers import DiffusionPipeline
9
 
10
  dtype = torch.bfloat16
 
21
  seed = random.randint(0, MAX_SEED)
22
  generator = torch.Generator().manual_seed(seed)
23
  image = pipe(
24
+ prompt=prompt,
25
+ width=width,
26
+ height=height,
27
+ num_inference_steps=num_inference_steps,
28
+ generator=generator,
29
  guidance_scale=0.0
30
+ ).images[0]
31
+ return image
32
+
33
  examples = [
34
+ ["a tiny astronaut hatching from an egg on the moon", 0, True, 1024, 1024, 4],
35
+ ["a cat holding a sign that says hello world", 0, True, 1024, 1024, 4],
36
+ ["an anime illustration of a wiener schnitzel", 0, True, 1024, 1024, 4],
37
  ]
38
 
39
+ css = """
40
  #col-container {
41
  margin: 0 auto;
42
  max-width: 520px;
43
  }
44
  """
45
 
46
+ description = """# FLUX.1 [schnell]
 
 
 
47
  12B param rectified flow transformer distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/) for 4 step generation
48
  [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-schnell)]
49
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ interface = CollectorInterface(
52
+ fn=infer,
53
+ inputs=[
54
+ gr.Textbox(label="Prompt", placeholder="Enter your prompt")
55
+ ],
56
+ outputs=[
57
+ gr.Image(label="Result"),
58
+ ],
59
+ additional_inputs=[
60
+ gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0),
61
+ gr.Checkbox(label="Randomize seed", value=True),
62
+ gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024),
63
+ gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024),
64
+ gr.Slider(label="Number of inference steps", minimum=1, maximum=50, step=1, value=4),
65
+ ],
66
+ title="FLUX.1 [schnell] - with Dataset Viber data collection",
67
+ description=description,
68
+ examples=examples,
69
+ css=css,
70
+ dataset_name="image-generation-flux1-schnell"
71
+ )
72
 
73
+ interface.launch()