ginipick commited on
Commit
3b53d1c
ยท
verified ยท
1 Parent(s): 16fda04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -16
app.py CHANGED
@@ -102,12 +102,14 @@ def generate(prompt,
102
  slider_x = [concept_2, concept_1]
103
  # check if avg diff for directions need to be re-calculated
104
  if randomize_seed:
105
- seed = random.randint(0, MAX_SEED)
106
 
107
  if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
108
  gradio_progress(0, desc="Calculating directions...")
109
  avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
110
  x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
 
 
111
 
112
  images = []
113
  high_scale = scale
@@ -135,13 +137,13 @@ def generate(prompt,
135
 
136
  video_path = f"{uuid.uuid4()}.mp4"
137
  print(video_path)
138
- return x_concept_1,x_concept_2, avg_diff_x, export_to_video(images, video_path, fps=5), canvas, images, images[scale_middle], post_generation_slider_update, seed
139
 
140
  def update_pre_generated_images(slider_value, total_images):
141
  number_images = 0
142
  if total_images:
143
  number_images = len(total_images)
144
- if(number_images > 0):
145
  scale_tuple = convert_to_centered_scale(number_images)
146
  return total_images[scale_tuple.index(slider_value)][0]
147
  else:
@@ -150,35 +152,71 @@ def update_pre_generated_images(slider_value, total_images):
150
  def reset_recalc_directions():
151
  return True
152
 
153
- # Updated examples with English text
 
 
154
  examples = [
155
- ["flower in mountain", "spring", "winter", 1.5],
156
- ["a tomato", "super fresh", "rotten", 2.5],
157
- ["์—ฌ์ž", "์•„๊ธฐ", "๋…ธ์ธ", 2.5]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  ]
159
 
160
-
 
 
161
  css = """
 
 
 
 
 
 
 
 
162
  footer {
163
  visibility: hidden;
164
  }
165
 
166
  .container {
167
  max-width: 1200px;
168
- margin: auto;
 
169
  }
170
 
171
  .main-panel {
172
- background-color: rgba(255, 255, 255, 0.05);
173
  border-radius: 12px;
174
  padding: 20px;
175
  margin-bottom: 20px;
 
176
  }
177
 
178
  .controls-panel {
179
- background-color: rgba(255, 255, 255, 0.02);
180
  border-radius: 8px;
181
  padding: 16px;
 
182
  }
183
 
184
  .image-display {
@@ -194,12 +232,12 @@ footer {
194
 
195
  .advanced-panel {
196
  margin-top: 20px;
197
- border-top: 1px solid rgba(255, 255, 255, 0.1);
198
  padding-top: 20px;
199
  }
200
  """
201
 
202
- with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
203
  x_concept_1 = gr.State("")
204
  x_concept_2 = gr.State("")
205
  total_images = gr.State([])
@@ -317,7 +355,7 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
317
  autoplay=True,
318
  height=100
319
  )
320
- with gr.Row(): # Moved this block to be after the video
321
  with gr.Column():
322
  post_generation_image = gr.Image(
323
  label=english_labels["Generated Images"],
@@ -333,7 +371,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
333
  label=english_labels["From 1st to 2nd direction"]
334
  )
335
 
336
-
337
  # Examples Section
338
  gr.Examples(
339
  examples=examples,
@@ -366,4 +403,4 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
366
  )
367
 
368
  if __name__ == "__main__":
369
- demo.launch()
 
102
  slider_x = [concept_2, concept_1]
103
  # check if avg diff for directions need to be re-calculated
104
  if randomize_seed:
105
+ seed = random.randint(0, MAX_SEED)
106
 
107
  if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
108
  gradio_progress(0, desc="Calculating directions...")
109
  avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
110
  x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
111
+ else:
112
+ avg_diff = avg_diff_x
113
 
114
  images = []
115
  high_scale = scale
 
137
 
138
  video_path = f"{uuid.uuid4()}.mp4"
139
  print(video_path)
140
+ return x_concept_1, x_concept_2, avg_diff_x, export_to_video(images, video_path, fps=5), canvas, images, images[scale_middle], post_generation_slider_update, seed
141
 
142
  def update_pre_generated_images(slider_value, total_images):
143
  number_images = 0
144
  if total_images:
145
  number_images = len(total_images)
146
+ if number_images > 0:
147
  scale_tuple = convert_to_centered_scale(number_images)
148
  return total_images[scale_tuple.index(slider_value)][0]
149
  else:
 
152
  def reset_recalc_directions():
153
  return True
154
 
155
+ # =======================
156
+ # ๊ฐœ์„ ๋œ ์˜ˆ์ œ ํ”„๋กฌํ”„ํŠธ
157
+ # =======================
158
  examples = [
159
+ [
160
+ "A serene mountain landscape with a gentle river flowing in the foreground under a bright blue sky.",
161
+ "Early Spring",
162
+ "Deep Winter",
163
+ 1.5
164
+ ],
165
+ [
166
+ "A bustling city street at dusk with neon lights reflecting on wet pavement, capturing the contrast between day and night.",
167
+ "Daytime",
168
+ "Nighttime",
169
+ 2.5
170
+ ],
171
+ [
172
+ "An abstract digital art composition featuring vibrant colors and dynamic shapes.",
173
+ "Calm",
174
+ "Energetic",
175
+ 2.0
176
+ ],
177
+ [
178
+ "์—ฌ์„ฑ์˜ ๋ฏธ์†Œ์™€ ํ•จ๊ป˜ํ•˜๋Š” ๋”ฐ๋œปํ•œ ๋ถ„์œ„๊ธฐ์˜ ์ธ๋ฌผ ์‚ฌ์ง„",
179
+ "์ Š์Œ",
180
+ "๋…ธ๋…„",
181
+ 2.5
182
+ ]
183
  ]
184
 
185
+ # =======================
186
+ # ๋ฐ๊ณ  ์„ธ๋ จ๋œ UI CSS
187
+ # =======================
188
  css = """
189
+ /* ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€์™€ ๋ฐ์€ ํ†ค ์ ์šฉ */
190
+ body {
191
+ background: #ffffff url('https://images.unsplash.com/photo-1506748686214-e9df14d4d9d0?ixlib=rb-1.2.1&auto=format&fit=crop&w=1600&q=80') no-repeat center center fixed;
192
+ background-size: cover;
193
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
194
+ color: #333;
195
+ }
196
+
197
  footer {
198
  visibility: hidden;
199
  }
200
 
201
  .container {
202
  max-width: 1200px;
203
+ margin: 20px auto;
204
+ padding: 0 10px;
205
  }
206
 
207
  .main-panel {
208
+ background-color: rgba(255, 255, 255, 0.9);
209
  border-radius: 12px;
210
  padding: 20px;
211
  margin-bottom: 20px;
212
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
213
  }
214
 
215
  .controls-panel {
216
+ background-color: rgba(255, 255, 255, 0.85);
217
  border-radius: 8px;
218
  padding: 16px;
219
+ box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
220
  }
221
 
222
  .image-display {
 
232
 
233
  .advanced-panel {
234
  margin-top: 20px;
235
+ border-top: 1px solid #eaeaea;
236
  padding-top: 20px;
237
  }
238
  """
239
 
240
+ with gr.Blocks(css=css) as demo:
241
  x_concept_1 = gr.State("")
242
  x_concept_2 = gr.State("")
243
  total_images = gr.State([])
 
355
  autoplay=True,
356
  height=100
357
  )
358
+ with gr.Row(): # Moved this block to be after the video
359
  with gr.Column():
360
  post_generation_image = gr.Image(
361
  label=english_labels["Generated Images"],
 
371
  label=english_labels["From 1st to 2nd direction"]
372
  )
373
 
 
374
  # Examples Section
375
  gr.Examples(
376
  examples=examples,
 
403
  )
404
 
405
  if __name__ == "__main__":
406
+ demo.launch()