CultriX commited on
Commit
4451d82
1 Parent(s): f2ffcc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -3,8 +3,8 @@ import numpy as np
3
  import random
4
  import spaces
5
  import torch
6
- from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, AutoencoderTiny, AutoencoderKL
7
- from transformers import CLIPTextModel, CLIPTokenizer, T5EncoderModel, T5TokenizerFast
8
  from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
9
 
10
  dtype = torch.bfloat16
@@ -20,8 +20,6 @@ MAX_IMAGE_SIZE = 2048
20
 
21
  pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
22
 
23
- history = []
24
-
25
  @spaces.GPU(duration=75)
26
  def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
27
  if randomize_seed:
@@ -38,16 +36,15 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
38
  output_type="pil",
39
  good_vae=good_vae,
40
  ):
41
- history.append((img, prompt, seed, width, height, guidance_scale, num_inference_steps))
42
  yield img, seed
43
-
44
  examples = [
45
  "a tiny astronaut hatching from an egg on the moon",
46
  "a cat holding a sign that says hello world",
47
  "an anime illustration of a wiener schnitzel",
48
  ]
49
 
50
- css = """
51
  #col-container {
52
  margin: 0 auto;
53
  max-width: 520px;
@@ -63,6 +60,7 @@ with gr.Blocks(css=css) as demo:
63
  """)
64
 
65
  with gr.Row():
 
66
  prompt = gr.Text(
67
  label="Prompt",
68
  show_label=False,
@@ -70,11 +68,13 @@ with gr.Blocks(css=css) as demo:
70
  placeholder="Enter your prompt",
71
  container=False,
72
  )
 
73
  run_button = gr.Button("Run", scale=0)
74
 
75
  result = gr.Image(label="Result", show_label=False)
76
 
77
  with gr.Accordion("Advanced Settings", open=False):
 
78
  seed = gr.Slider(
79
  label="Seed",
80
  minimum=0,
@@ -82,9 +82,11 @@ with gr.Blocks(css=css) as demo:
82
  step=1,
83
  value=0,
84
  )
 
85
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
86
 
87
  with gr.Row():
 
88
  width = gr.Slider(
89
  label="Width",
90
  minimum=256,
@@ -92,6 +94,7 @@ with gr.Blocks(css=css) as demo:
92
  step=32,
93
  value=1024,
94
  )
 
95
  height = gr.Slider(
96
  label="Height",
97
  minimum=256,
@@ -101,6 +104,7 @@ with gr.Blocks(css=css) as demo:
101
  )
102
 
103
  with gr.Row():
 
104
  guidance_scale = gr.Slider(
105
  label="Guidance Scale",
106
  minimum=1,
@@ -108,6 +112,7 @@ with gr.Blocks(css=css) as demo:
108
  step=0.1,
109
  value=3.5,
110
  )
 
111
  num_inference_steps = gr.Slider(
112
  label="Number of inference steps",
113
  minimum=1,
@@ -117,26 +122,18 @@ with gr.Blocks(css=css) as demo:
117
  )
118
 
119
  gr.Examples(
120
- examples=examples,
121
- fn=infer,
122
- inputs=[prompt],
123
- outputs=[result, seed],
124
  cache_examples="lazy"
125
  )
126
 
127
- def show_history():
128
- return [(img, f"Prompt: {p}, Seed: {s}, Width: {w}, Height: {h}, Guidance Scale: {g}, Steps: {n}") for img, p, s, w, h, g, n in history]
129
-
130
- history_button = gr.Button("Show History")
131
- history_gallery = gr.Gallery(label="History").scale(2)
132
-
133
- history_button.click(fn=show_history, inputs=[], outputs=[history_gallery])
134
-
135
  gr.on(
136
  triggers=[run_button.click, prompt.submit],
137
- fn=infer,
138
- inputs=[prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
139
- outputs=[result, seed]
140
  )
141
 
142
- demo.launch()
 
3
  import random
4
  import spaces
5
  import torch
6
+ from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, AutoencoderTiny, AutoencoderKL
7
+ from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
8
  from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
9
 
10
  dtype = torch.bfloat16
 
20
 
21
  pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
22
 
 
 
23
  @spaces.GPU(duration=75)
24
  def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
25
  if randomize_seed:
 
36
  output_type="pil",
37
  good_vae=good_vae,
38
  ):
 
39
  yield img, seed
40
+
41
  examples = [
42
  "a tiny astronaut hatching from an egg on the moon",
43
  "a cat holding a sign that says hello world",
44
  "an anime illustration of a wiener schnitzel",
45
  ]
46
 
47
+ css="""
48
  #col-container {
49
  margin: 0 auto;
50
  max-width: 520px;
 
60
  """)
61
 
62
  with gr.Row():
63
+
64
  prompt = gr.Text(
65
  label="Prompt",
66
  show_label=False,
 
68
  placeholder="Enter your prompt",
69
  container=False,
70
  )
71
+
72
  run_button = gr.Button("Run", scale=0)
73
 
74
  result = gr.Image(label="Result", show_label=False)
75
 
76
  with gr.Accordion("Advanced Settings", open=False):
77
+
78
  seed = gr.Slider(
79
  label="Seed",
80
  minimum=0,
 
82
  step=1,
83
  value=0,
84
  )
85
+
86
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
87
 
88
  with gr.Row():
89
+
90
  width = gr.Slider(
91
  label="Width",
92
  minimum=256,
 
94
  step=32,
95
  value=1024,
96
  )
97
+
98
  height = gr.Slider(
99
  label="Height",
100
  minimum=256,
 
104
  )
105
 
106
  with gr.Row():
107
+
108
  guidance_scale = gr.Slider(
109
  label="Guidance Scale",
110
  minimum=1,
 
112
  step=0.1,
113
  value=3.5,
114
  )
115
+
116
  num_inference_steps = gr.Slider(
117
  label="Number of inference steps",
118
  minimum=1,
 
122
  )
123
 
124
  gr.Examples(
125
+ examples = examples,
126
+ fn = infer,
127
+ inputs = [prompt],
128
+ outputs = [result, seed],
129
  cache_examples="lazy"
130
  )
131
 
 
 
 
 
 
 
 
 
132
  gr.on(
133
  triggers=[run_button.click, prompt.submit],
134
+ fn = infer,
135
+ inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
136
+ outputs = [result, seed]
137
  )
138
 
139
+ demo.launch()