openfree commited on
Commit
962bf3d
Β·
verified Β·
1 Parent(s): 12996e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -49
app.py CHANGED
@@ -50,6 +50,47 @@ system_prompt_i2v = """당신은 이미지 기반 λΉ„λ””μ˜€ 생성을 μœ„ν•œ ν”„
50
  촬영 감독이 촬영 λͺ©λ‘μ„ μ„€λͺ…ν•˜λŠ” κ²ƒμ²˜λŸΌ ꡬ체적이고 μ‹œκ°μ μœΌλ‘œ μž‘μ„±ν•˜μ„Έμš”.
51
  200단어λ₯Ό λ„˜μ§€ μ•Šλ„λ‘ ν•˜λ˜, μ΅œλŒ€ν•œ μƒμ„Έν•˜κ²Œ μž‘μ„±ν•˜μ„Έμš”."""
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Load Hugging Face token if needed
54
  hf_token = os.getenv("HF_TOKEN")
55
  openai_api_key = os.getenv("OPENAI_API_KEY")
@@ -195,40 +236,9 @@ pipeline = XoraVideoPipeline(
195
  vae=vae,
196
  ).to(device)
197
 
198
- # Preset options for resolution and frame configuration
199
- # Convert frames to seconds assuming 25 FPS
200
- preset_options = [
201
- {"label": "1216x704, 1.6초", "width": 1216, "height": 704, "num_frames": 41},
202
- {"label": "1088x704, 2.0초", "width": 1088, "height": 704, "num_frames": 49},
203
- {"label": "1056x640, 2.3초", "width": 1056, "height": 640, "num_frames": 57},
204
- {"label": "992x608, 2.6초", "width": 992, "height": 608, "num_frames": 65},
205
- {"label": "896x608, 2.9초", "width": 896, "height": 608, "num_frames": 73},
206
- {"label": "896x544, 3.2초", "width": 896, "height": 544, "num_frames": 81},
207
- {"label": "832x544, 3.6초", "width": 832, "height": 544, "num_frames": 89},
208
- {"label": "800x512, 3.9초", "width": 800, "height": 512, "num_frames": 97},
209
- {"label": "768x512, 3.9초", "width": 768, "height": 512, "num_frames": 97},
210
- {"label": "800x480, 4.2초", "width": 800, "height": 480, "num_frames": 105},
211
- {"label": "736x480, 4.5초", "width": 736, "height": 480, "num_frames": 113},
212
- {"label": "704x480, 4.8초", "width": 704, "height": 480, "num_frames": 121},
213
- {"label": "704x448, 5.2초", "width": 704, "height": 448, "num_frames": 129},
214
- {"label": "672x448, 5.5초", "width": 672, "height": 448, "num_frames": 137},
215
- {"label": "640x416, 6.1초", "width": 640, "height": 416, "num_frames": 153},
216
- {"label": "672x384, 6.4초", "width": 672, "height": 384, "num_frames": 161},
217
- {"label": "640x384, 6.8초", "width": 640, "height": 384, "num_frames": 169},
218
- {"label": "608x384, 7.1초", "width": 608, "height": 384, "num_frames": 177},
219
- {"label": "576x384, 7.4초", "width": 576, "height": 384, "num_frames": 185},
220
- {"label": "608x352, 7.7초", "width": 608, "height": 352, "num_frames": 193},
221
- {"label": "576x352, 8.0초", "width": 576, "height": 352, "num_frames": 201},
222
- {"label": "544x352, 8.4초", "width": 544, "height": 352, "num_frames": 209},
223
- {"label": "512x352, 9.3초", "width": 512, "height": 352, "num_frames": 233},
224
- {"label": "544x320, 9.6초", "width": 544, "height": 320, "num_frames": 241},
225
- {"label": "512x320, 10.3초", "width": 512, "height": 320, "num_frames": 257},
226
- ]
227
-
228
  def preset_changed(preset):
229
  if preset != "Custom":
230
  selected = next(item for item in preset_options if item["label"] == preset)
231
- # height, width, num_frames 값을 global λ³€μˆ˜λ‘œ μ—…λ°μ΄νŠΈ
232
  return (
233
  selected["height"],
234
  selected["width"],
@@ -247,7 +257,6 @@ def preset_changed(preset):
247
  gr.update(visible=True),
248
  )
249
 
250
-
251
  def generate_video_from_text(
252
  prompt="",
253
  enhance_prompt_toggle=False,
@@ -301,8 +310,7 @@ def generate_video_from_text(
301
  vae_per_channel_normalize=True,
302
  conditioning_method=ConditioningMethod.UNCONDITIONAL,
303
  mixed_precision=True,
304
- callback_on_step_end=gradio_progress_callback,
305
- ).images
306
  except Exception as e:
307
  raise gr.Error(
308
  f"λΉ„λ””μ˜€ 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”. 였λ₯˜: {e}",
@@ -445,17 +453,17 @@ def create_advanced_options():
445
  )
446
  height_slider = gr.Slider(
447
  label="4.4 Height",
448
- minimum=256,
449
- maximum=1024,
450
- step=64,
451
  value=512,
452
  visible=False,
453
  )
454
  width_slider = gr.Slider(
455
  label="4.5 Width",
456
- minimum=256,
457
- maximum=1024,
458
- step=64,
459
  value=768,
460
  visible=False,
461
  )
@@ -505,13 +513,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
505
  )
506
 
507
  # ν˜„μž¬ μ„ νƒλœ 값듀을 μ €μž₯ν•  μƒνƒœ λ³€μˆ˜λ“€
508
- txt2vid_current_height = gr.State(value=512)
509
- txt2vid_current_width = gr.State(value=320)
510
- txt2vid_current_num_frames = gr.State(value=257)
511
 
512
  txt2vid_preset = gr.Dropdown(
513
  choices=[p["label"] for p in preset_options],
514
- value="512x320, 10.3초",
515
  label="Step 2: 해상도 프리셋 선택",
516
  )
517
 
@@ -563,13 +571,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
563
  )
564
 
565
  # ν˜„μž¬ μ„ νƒλœ 값듀을 μ €μž₯ν•  μƒνƒœ λ³€μˆ˜λ“€
566
- img2vid_current_height = gr.State(value=512)
567
- img2vid_current_width = gr.State(value=768)
568
- img2vid_current_num_frames = gr.State(value=97)
569
 
570
  img2vid_preset = gr.Dropdown(
571
  choices=[p["label"] for p in preset_options],
572
- value="512x320, 10.3초",
573
  label="Step 3: 해상도 프리셋 선택",
574
  )
575
 
@@ -667,4 +675,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
667
  if __name__ == "__main__":
668
  iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
669
  share=True, show_api=False
670
- )
 
50
  촬영 감독이 촬영 λͺ©λ‘μ„ μ„€λͺ…ν•˜λŠ” κ²ƒμ²˜λŸΌ ꡬ체적이고 μ‹œκ°μ μœΌλ‘œ μž‘μ„±ν•˜μ„Έμš”.
51
  200단어λ₯Ό λ„˜μ§€ μ•Šλ„λ‘ ν•˜λ˜, μ΅œλŒ€ν•œ μƒμ„Έν•˜κ²Œ μž‘μ„±ν•˜μ„Έμš”."""
52
 
53
+ # Updated preset options
54
+ preset_options = [
55
+ # 16:9 λΉ„μœ¨ (μ΅œλŒ€/μ΅œμ†Œ)
56
+ {"label": "16:9 HD (1216x684)", "width": 1216, "height": 684, "num_frames": 41, "aspect": "16:9"},
57
+ {"label": "16:9 (640x360)", "width": 640, "height": 360, "num_frames": 81, "aspect": "16:9"},
58
+
59
+ # 4:3 λΉ„μœ¨ (μ΅œλŒ€/μ΅œμ†Œ)
60
+ {"label": "4:3 (1024x768)", "width": 1024, "height": 768, "num_frames": 49, "aspect": "4:3"},
61
+ {"label": "4:3 (640x480)", "width": 640, "height": 480, "num_frames": 73, "aspect": "4:3"},
62
+
63
+ # 1:1 λΉ„μœ¨ (μ΅œλŒ€/μ΅œμ†Œ)
64
+ {"label": "1:1 (896x896)", "width": 896, "height": 896, "num_frames": 57, "aspect": "1:1"},
65
+ {"label": "1:1 (512x512)", "width": 512, "height": 512, "num_frames": 81, "aspect": "1:1"},
66
+
67
+ # 3:2 λΉ„μœ¨ (μ΅œλŒ€)
68
+ {"label": "3:2 (1200x800)", "width": 1200, "height": 800, "num_frames": 49, "aspect": "3:2"},
69
+
70
+ # 9:16 λΉ„μœ¨ (μ΅œμ†Œ)
71
+ {"label": "9:16 (432x768)", "width": 432, "height": 768, "num_frames": 81, "aspect": "9:16"},
72
+
73
+ # μ»€μŠ€ν…€ μ˜΅μ…˜
74
+ {"label": "Custom", "width": None, "height": None, "num_frames": None, "aspect": "custom"}
75
+ ]
76
+
77
+ # Custom constraints
78
+ custom_constraints = {
79
+ "width": {
80
+ "min": 512,
81
+ "max": 1216,
82
+ "step": 64
83
+ },
84
+ "height": {
85
+ "min": 320,
86
+ "max": 896,
87
+ "step": 64
88
+ }
89
+ }
90
+
91
+ # Default preset
92
+ default_preset = "16:9 (640x360)"
93
+
94
  # Load Hugging Face token if needed
95
  hf_token = os.getenv("HF_TOKEN")
96
  openai_api_key = os.getenv("OPENAI_API_KEY")
 
236
  vae=vae,
237
  ).to(device)
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  def preset_changed(preset):
240
  if preset != "Custom":
241
  selected = next(item for item in preset_options if item["label"] == preset)
 
242
  return (
243
  selected["height"],
244
  selected["width"],
 
257
  gr.update(visible=True),
258
  )
259
 
 
260
  def generate_video_from_text(
261
  prompt="",
262
  enhance_prompt_toggle=False,
 
310
  vae_per_channel_normalize=True,
311
  conditioning_method=ConditioningMethod.UNCONDITIONAL,
312
  mixed_precision=True,
313
+ callback_on_step_end=gradio_progress_callback,).images
 
314
  except Exception as e:
315
  raise gr.Error(
316
  f"λΉ„λ””μ˜€ 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€. λ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”. 였λ₯˜: {e}",
 
453
  )
454
  height_slider = gr.Slider(
455
  label="4.4 Height",
456
+ minimum=custom_constraints["height"]["min"],
457
+ maximum=custom_constraints["height"]["max"],
458
+ step=custom_constraints["height"]["step"],
459
  value=512,
460
  visible=False,
461
  )
462
  width_slider = gr.Slider(
463
  label="4.5 Width",
464
+ minimum=custom_constraints["width"]["min"],
465
+ maximum=custom_constraints["width"]["max"],
466
+ step=custom_constraints["width"]["step"],
467
  value=768,
468
  visible=False,
469
  )
 
513
  )
514
 
515
  # ν˜„μž¬ μ„ νƒλœ 값듀을 μ €μž₯ν•  μƒνƒœ λ³€μˆ˜λ“€
516
+ txt2vid_current_height = gr.State(value=360)
517
+ txt2vid_current_width = gr.State(value=640)
518
+ txt2vid_current_num_frames = gr.State(value=81)
519
 
520
  txt2vid_preset = gr.Dropdown(
521
  choices=[p["label"] for p in preset_options],
522
+ value=default_preset,
523
  label="Step 2: 해상도 프리셋 선택",
524
  )
525
 
 
571
  )
572
 
573
  # ν˜„μž¬ μ„ νƒλœ 값듀을 μ €μž₯ν•  μƒνƒœ λ³€μˆ˜λ“€
574
+ img2vid_current_height = gr.State(value=360)
575
+ img2vid_current_width = gr.State(value=640)
576
+ img2vid_current_num_frames = gr.State(value=81)
577
 
578
  img2vid_preset = gr.Dropdown(
579
  choices=[p["label"] for p in preset_options],
580
+ value=default_preset,
581
  label="Step 3: 해상도 프리셋 선택",
582
  )
583
 
 
675
  if __name__ == "__main__":
676
  iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(
677
  share=True, show_api=False
678
+ )