CultriX commited on
Commit
63731aa
1 Parent(s): 76d8871

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
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,6 +20,9 @@ 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
  @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,15 +39,17 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
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,7 +65,6 @@ with gr.Blocks(css=css) as demo:
60
  """)
61
 
62
  with gr.Row():
63
-
64
  prompt = gr.Text(
65
  label="Prompt",
66
  show_label=False,
@@ -68,13 +72,11 @@ with gr.Blocks(css=css) as demo:
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,11 +84,9 @@ with gr.Blocks(css=css) as demo:
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,7 +94,6 @@ with gr.Blocks(css=css) as demo:
94
  step=32,
95
  value=1024,
96
  )
97
-
98
  height = gr.Slider(
99
  label="Height",
100
  minimum=256,
@@ -104,7 +103,6 @@ with gr.Blocks(css=css) as demo:
104
  )
105
 
106
  with gr.Row():
107
-
108
  guidance_scale = gr.Slider(
109
  label="Guidance Scale",
110
  minimum=1,
@@ -112,7 +110,6 @@ with gr.Blocks(css=css) as demo:
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,18 +119,27 @@ with gr.Blocks(css=css) as demo:
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()
 
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
+ # History to keep track of generated images and their parameters
24
+ history = []
25
+
26
  @spaces.GPU(duration=75)
27
  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)):
28
  if randomize_seed:
 
39
  output_type="pil",
40
  good_vae=good_vae,
41
  ):
42
+ # Save to history
43
+ history.append((img, prompt, seed, width, height, guidance_scale, num_inference_steps))
44
  yield img, seed
45
+
46
  examples = [
47
  "a tiny astronaut hatching from an egg on the moon",
48
  "a cat holding a sign that says hello world",
49
  "an anime illustration of a wiener schnitzel",
50
  ]
51
 
52
+ css = """
53
  #col-container {
54
  margin: 0 auto;
55
  max-width: 520px;
 
65
  """)
66
 
67
  with gr.Row():
 
68
  prompt = gr.Text(
69
  label="Prompt",
70
  show_label=False,
 
72
  placeholder="Enter your prompt",
73
  container=False,
74
  )
 
75
  run_button = gr.Button("Run", scale=0)
76
 
77
  result = gr.Image(label="Result", show_label=False)
78
 
79
  with gr.Accordion("Advanced Settings", open=False):
 
80
  seed = gr.Slider(
81
  label="Seed",
82
  minimum=0,
 
84
  step=1,
85
  value=0,
86
  )
 
87
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
88
 
89
  with gr.Row():
 
90
  width = gr.Slider(
91
  label="Width",
92
  minimum=256,
 
94
  step=32,
95
  value=1024,
96
  )
 
97
  height = gr.Slider(
98
  label="Height",
99
  minimum=256,
 
103
  )
104
 
105
  with gr.Row():
 
106
  guidance_scale = gr.Slider(
107
  label="Guidance Scale",
108
  minimum=1,
 
110
  step=0.1,
111
  value=3.5,
112
  )
 
113
  num_inference_steps = gr.Slider(
114
  label="Number of inference steps",
115
  minimum=1,
 
119
  )
120
 
121
  gr.Examples(
122
+ examples=examples,
123
+ fn=infer,
124
+ inputs=[prompt],
125
+ outputs=[result, seed],
126
  cache_examples="lazy"
127
  )
128
 
129
+ # History button to display previous images and parameters
130
+ def show_history():
131
+ 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]
132
+
133
+ history_button = gr.Button("Show History")
134
+ history_gallery = gr.Gallery(label="History").style(grid=[2, 2], height="auto")
135
+
136
+ history_button.click(fn=show_history, inputs=[], outputs=[history_gallery])
137
+
138
  gr.on(
139
  triggers=[run_button.click, prompt.submit],
140
+ fn=infer,
141
+ inputs=[prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
142
+ outputs=[result, seed]
143
  )
144
 
145
+ demo.launch()