Spaces:
Running
Running
Update app.py
Browse files
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=
|
449 |
-
maximum=
|
450 |
-
step=
|
451 |
value=512,
|
452 |
visible=False,
|
453 |
)
|
454 |
width_slider = gr.Slider(
|
455 |
label="4.5 Width",
|
456 |
-
minimum=
|
457 |
-
maximum=
|
458 |
-
step=
|
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=
|
509 |
-
txt2vid_current_width = gr.State(value=
|
510 |
-
txt2vid_current_num_frames = gr.State(value=
|
511 |
|
512 |
txt2vid_preset = gr.Dropdown(
|
513 |
choices=[p["label"] for p in preset_options],
|
514 |
-
value=
|
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=
|
567 |
-
img2vid_current_width = gr.State(value=
|
568 |
-
img2vid_current_num_frames = gr.State(value=
|
569 |
|
570 |
img2vid_preset = gr.Dropdown(
|
571 |
choices=[p["label"] for p in preset_options],
|
572 |
-
value=
|
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 |
+
)
|