This PR allows to choose the output format

#1
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -16,7 +16,7 @@ MAX_IMAGE_SIZE = 2048
16
 
17
 
18
  @spaces.GPU()
19
- 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)):
20
  if randomize_seed:
21
  seed = random.randint(0, MAX_SEED)
22
  generator = torch.Generator().manual_seed(seed)
@@ -28,7 +28,7 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
28
  generator = generator,
29
  guidance_scale=guidance_scale
30
  ).images[0]
31
- return image, seed
32
 
33
  examples = [
34
  "a tiny astronaut hatching from an egg on the moon",
@@ -50,16 +50,15 @@ with gr.Blocks(css=css, delete_cache=(4000, 4000)) as demo:
50
  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/)
51
  """)
52
 
53
- with gr.Row():
54
-
55
- prompt = gr.Text(
56
  label="Prompt",
57
  show_label=False,
58
  max_lines=1,
59
  placeholder="Enter your prompt",
60
  container=False,
61
  )
62
- run_button = gr.Button("Run", scale=0)
 
63
 
64
  num_inference_steps = gr.Slider(
65
  label="Number of inference steps",
@@ -73,16 +72,6 @@ Merge by [Sayak Paul](https://huggingface.co/sayakpaul) of 2 of the 12B param re
73
 
74
  with gr.Accordion("Advanced Settings", open=False):
75
 
76
- seed = gr.Slider(
77
- label="Seed",
78
- minimum=0,
79
- maximum=MAX_SEED,
80
- step=1,
81
- value=0,
82
- )
83
-
84
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
85
-
86
  with gr.Row():
87
 
88
  width = gr.Slider(
@@ -101,15 +90,25 @@ Merge by [Sayak Paul](https://huggingface.co/sayakpaul) of 2 of the 12B param re
101
  value=1024,
102
  )
103
 
104
- with gr.Row():
105
-
106
- guidance_scale = gr.Slider(
107
- label="Guidance Scale",
108
- minimum=1,
109
- maximum=15,
110
- step=0.1,
111
- value=3.5,
112
- )
 
 
 
 
 
 
 
 
 
 
113
 
114
  gr.Examples(
115
  examples = examples,
@@ -122,7 +121,7 @@ Merge by [Sayak Paul](https://huggingface.co/sayakpaul) of 2 of the 12B param re
122
  gr.on(
123
  triggers=[run_button.click, prompt.submit],
124
  fn = infer,
125
- inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
126
  outputs = [result, seed]
127
  )
128
 
 
16
 
17
 
18
  @spaces.GPU()
19
+ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=8, output_format="png", progress=gr.Progress(track_tqdm=True)):
20
  if randomize_seed:
21
  seed = random.randint(0, MAX_SEED)
22
  generator = torch.Generator().manual_seed(seed)
 
28
  generator = generator,
29
  guidance_scale=guidance_scale
30
  ).images[0]
31
+ return gr.update(format = output_format, value = image), seed
32
 
33
  examples = [
34
  "a tiny astronaut hatching from an egg on the moon",
 
50
  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/)
51
  """)
52
 
53
+ prompt = gr.Text(
 
 
54
  label="Prompt",
55
  show_label=False,
56
  max_lines=1,
57
  placeholder="Enter your prompt",
58
  container=False,
59
  )
60
+
61
+ run_button = gr.Button("Run", scale=0, variant="primary")
62
 
63
  num_inference_steps = gr.Slider(
64
  label="Number of inference steps",
 
72
 
73
  with gr.Accordion("Advanced Settings", open=False):
74
 
 
 
 
 
 
 
 
 
 
 
75
  with gr.Row():
76
 
77
  width = gr.Slider(
 
90
  value=1024,
91
  )
92
 
93
+ guidance_scale = gr.Slider(
94
+ label="Guidance Scale",
95
+ minimum=1,
96
+ maximum=15,
97
+ step=0.1,
98
+ value=3.5,
99
+ )
100
+
101
+ output_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="png", interactive=True)
102
+
103
+ seed = gr.Slider(
104
+ label="Seed",
105
+ minimum=0,
106
+ maximum=MAX_SEED,
107
+ step=1,
108
+ value=0,
109
+ )
110
+
111
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
112
 
113
  gr.Examples(
114
  examples = examples,
 
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, output_format],
125
  outputs = [result, seed]
126
  )
127