helblazer811 commited on
Commit
5f5f2bb
·
1 Parent(s): 03aa30c

Auto load an image

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -5,7 +5,7 @@ import math
5
 
6
  from concept_attention import ConceptAttentionFluxPipeline
7
 
8
- IMG_SIZE = 250
9
  COLUMNS = 5
10
 
11
  EXAMPLES = [
@@ -67,6 +67,8 @@ def process_inputs(prompt, word_list, seed, layer_start_index, timestep_start_in
67
 
68
  num_rows = math.ceil(len(all_images_and_labels) / COLUMNS)
69
 
 
 
70
  return all_images_and_labels, num_rows
71
 
72
  with gr.Blocks(
@@ -97,7 +99,7 @@ with gr.Blocks(
97
  placeholder="Enter your prompt",
98
  value=EXAMPLES[0][0],
99
  scale=4,
100
- show_label=True,
101
  container=False
102
  # height="80px"
103
  )
@@ -106,7 +108,7 @@ with gr.Blocks(
106
  placeholder="Enter a list of concepts (comma-separated)",
107
  value=EXAMPLES[0][1],
108
  scale=4,
109
- show_label=True,
110
  container=False
111
  # height="80px"
112
  )
@@ -116,15 +118,18 @@ with gr.Blocks(
116
  scale=1
117
  )
118
 
 
 
119
  # generated_image = gr.Image(label="Generated Image", elem_classes="input-image")
120
  gallery = gr.Gallery(
121
  label="Generated images",
122
  show_label=True,
123
  # elem_id="gallery",
124
- columns=[COLUMNS],
125
- rows=[1],
126
- object_fit="contain",
127
- # height="auto"
 
128
  )
129
  with gr.Accordion("Advanced Settings", open=False):
130
  seed = gr.Slider(minimum=0, maximum=10000, step=1, label="Seed", value=42)
@@ -135,13 +140,19 @@ with gr.Blocks(
135
  submit_btn.click(
136
  fn=process_inputs,
137
  inputs=[prompt, words, seed, layer_start_index, timestep_start_index],
138
- outputs=[gallery, gallery.update(rows=True)]
139
  )
140
 
141
- gr.Examples(examples=EXAMPLES, inputs=[prompt, words, seed, layer_start_index, timestep_start_index], outputs=[gallery, gallery.update(rows=True)], fn=process_inputs, cache_examples=False)
 
 
 
 
 
 
142
 
143
  # Automatically process the first example on launch
144
- # demo.load(process_inputs, inputs=[prompt, words, seed, layer_start_index, timestep_start_index], outputs=[gallery])
145
 
146
 
147
  if __name__ == "__main__":
 
5
 
6
  from concept_attention import ConceptAttentionFluxPipeline
7
 
8
+ IMG_SIZE = 210
9
  COLUMNS = 5
10
 
11
  EXAMPLES = [
 
67
 
68
  num_rows = math.ceil(len(all_images_and_labels) / COLUMNS)
69
 
70
+ print(num_rows)
71
+
72
  return all_images_and_labels, num_rows
73
 
74
  with gr.Blocks(
 
99
  placeholder="Enter your prompt",
100
  value=EXAMPLES[0][0],
101
  scale=4,
102
+ # show_label=True,
103
  container=False
104
  # height="80px"
105
  )
 
108
  placeholder="Enter a list of concepts (comma-separated)",
109
  value=EXAMPLES[0][1],
110
  scale=4,
111
+ # show_label=True,
112
  container=False
113
  # height="80px"
114
  )
 
118
  scale=1
119
  )
120
 
121
+ num_rows_state = gr.State(value=1) # Initial number of rows
122
+
123
  # generated_image = gr.Image(label="Generated Image", elem_classes="input-image")
124
  gallery = gr.Gallery(
125
  label="Generated images",
126
  show_label=True,
127
  # elem_id="gallery",
128
+ columns=COLUMNS,
129
+ rows=1,
130
+ # object_fit="contain",
131
+ height="auto",
132
+ elem_classes="gallery"
133
  )
134
  with gr.Accordion("Advanced Settings", open=False):
135
  seed = gr.Slider(minimum=0, maximum=10000, step=1, label="Seed", value=42)
 
140
  submit_btn.click(
141
  fn=process_inputs,
142
  inputs=[prompt, words, seed, layer_start_index, timestep_start_index],
143
+ outputs=[gallery, num_rows_state]
144
  )
145
 
146
+ gr.Examples(examples=EXAMPLES, inputs=[prompt, words, seed, layer_start_index, timestep_start_index], outputs=[gallery, num_rows_state], fn=process_inputs, cache_examples=False)
147
+
148
+ # num_rows_state.change(
149
+ # fn=lambda rows: gr.Gallery.update(rows=int(rows)),
150
+ # inputs=[num_rows_state],
151
+ # outputs=[gallery]
152
+ # )
153
 
154
  # Automatically process the first example on launch
155
+ demo.load(process_inputs, inputs=[prompt, words, seed, layer_start_index, timestep_start_index], outputs=[gallery, num_rows_state])
156
 
157
 
158
  if __name__ == "__main__":