import os
import replicate
==========================================
1. API KEY
==========================================
Đặt API key vào biến môi trường:
Windows PowerShell:
$env:REPLICATE_API_TOKEN="YOUR_API_KEY"
if "REPLICATE_API_TOKEN" not in os.environ:
raise RuntimeError(
"Chưa có REPLICATE_API_TOKEN. "
"Hãy tạo API key trên Replicate và đặt vào biến môi trường."
)
==========================================
2. THƯ MỤC
==========================================
IMAGE_DIR = "images"
VIDEO_DIR = "videos"
os.makedirs(VIDEO_DIR, exist_ok=True)
==========================================
3. CHUYỂN ĐỘNG CHO 10 CẢNH
==========================================
PROMPTS = {
1: """
Students naturally walk through the school gate in the morning.
Several students smile, wave and greet each other.
Backpacks move naturally while walking.
Tree leaves and flowers gently move in the breeze.
Smooth cinematic camera slowly moves forward.
Keep the school building, students, uniforms and faces consistent.
Realistic human motion, natural body movement, joyful educational atmosphere.
16:9.
""",
2: """
Vietnamese middle school students walk together across the courtyard.
They laugh, talk and make friendly gestures.
Two students greet each other naturally.
Hands and arms move naturally while walking.
Other students continue walking in the background.
Smooth cinematic tracking camera.
Natural facial expressions and realistic body movement.
Keep the original characters and school environment consistent.
16:9.
""",
3: """
A Vietnamese teacher warmly greets students at the classroom door.
Students naturally stop and respectfully greet the teacher.
The teacher smiles and gently nods.
Students move their hands naturally.
Subtle classroom background movement.
Smooth cinematic camera movement toward the classroom.
Keep faces, uniforms and classroom unchanged.
Realistic human motion.
16:9.
""",
4: """
A Vietnamese middle school teacher explains a lesson.
Students actively participate and raise their hands.
Several students naturally move their hands and discuss ideas.
The teacher gestures naturally while explaining.
Students look at the teacher and classroom board.
Subtle camera movement from left to right.
Natural human movement and realistic facial expressions.
Keep the original classroom and characters consistent.
16:9.
""",
5: """
A student accidentally drops books and notebooks in the corridor.
Two classmates immediately walk toward the student and bend down.
They naturally pick up the books together.
The students smile and look at each other.
Books and hands move naturally.
Smooth cinematic camera tracking shot.
Warm emotional atmosphere.
Keep characters and school corridor consistent.
16:9.
""",
6: """
A student realizes a mistake in the classroom.
The student respectfully stands and apologizes to the teacher.
The teacher smiles kindly and gently encourages the student.
Classmates react positively and smile.
Natural gestures, head movement and facial expressions.
Slow cinematic camera movement.
Educational atmosphere about responsibility and correcting mistakes.
Keep the characters and classroom consistent.
16:9.
""",
7: """
Energetic Vietnamese middle school students perform a synchronized activity
in the school courtyard.
Students clap their hands and move rhythmically together.
Their arms and bodies move naturally to the music.
They smile confidently and enthusiastically.
Dynamic cinematic camera movement.
Youthful school music video atmosphere.
Keep the same students and uniforms consistent.
16:9.
""",
8: """
Students from different classes participate in a team-building activity.
They move together, cooperate and encourage one another.
Some students clap while others move through the activity.
Teachers observe and support the students.
Natural running, walking, hand and body movements.
Smooth cinematic camera tracking.
Joyful school community atmosphere.
Keep the school environment and characters consistent.
16:9.
""",
9: """
Wide aerial cinematic view of the school courtyard.
Many students and teachers participate in a joyful school activity.
Students naturally move and interact in organized groups.
Some students wave and raise their hands.
Trees gently move in the wind.
Slow cinematic aerial camera movement.
Warm sunlight and inspirational atmosphere.
Keep the school building and overall composition consistent.
16:9.
""",
10: """
Vietnamese middle school students stand together with their teachers.
Everyone smiles confidently toward the camera.
Students make subtle natural movements.
Teachers gently wave or nod.
Hair and clothing move slightly in the breeze.
Camera slowly moves backward from a close-up to a wide shot.
Emotional inspirational ending.
Keep all characters and the school building consistent.
Leave clean space for Vietnamese text.
16:9.
"""
}
==========================================
4. HÀM TẠO VIDEO
==========================================
def create_video(scene_number):
image_path = os.path.join(
IMAGE_DIR,
f"canh{scene_number:02d}.png"
)
if not os.path.exists(image_path):
print(f"❌ Không tìm thấy: {image_path}")
return
print()
print("=" * 60)
print(f"🎬 ĐANG TẠO CẢNH {scene_number}")
print("=" * 60)
with open(image_path, "rb") as image_file:
output = replicate.run(
"wavespeedai/wan-2.1-i2v-480p",
input={
"image": image_file,
"prompt": PROMPTS[scene_number],
"aspect_ratio": "16:9",
"seed": 12345 + scene_number
}
)
# Lưu video
output_path = os.path.join(
VIDEO_DIR,
f"canh{scene_number:02d}.mp4"
)
with open(output_path, "wb") as video_file:
video_file.write(output.read())
print(f"✅ Đã tạo: {output_path}")
==========================================
5. TẠO TOÀN BỘ 10 CẢNH
==========================================
for scene in range(1, 11):
try:
create_video(scene)
except Exception as e:
print()
print(f"❌ Lỗi cảnh {scene}:")
print(e)
print()
print("=" * 60)
print("🎉 HOÀN THÀNH 10 CẢNH")
print("=" * 60)
import os
import replicate
==========================================
1. API KEY
==========================================
Đặt API key vào biến môi trường:
Windows PowerShell:
$env:REPLICATE_API_TOKEN="YOUR_API_KEY"
if "REPLICATE_API_TOKEN" not in os.environ:
raise RuntimeError(
"Chưa có REPLICATE_API_TOKEN. "
"Hãy tạo API key trên Replicate và đặt vào biến môi trường."
)
==========================================
2. THƯ MỤC
==========================================
IMAGE_DIR = "images"
VIDEO_DIR = "videos"
os.makedirs(VIDEO_DIR, exist_ok=True)
==========================================
3. CHUYỂN ĐỘNG CHO 10 CẢNH
==========================================
PROMPTS = {
1: """
Students naturally walk through the school gate in the morning.
Several students smile, wave and greet each other.
Backpacks move naturally while walking.
Tree leaves and flowers gently move in the breeze.
Smooth cinematic camera slowly moves forward.
Keep the school building, students, uniforms and faces consistent.
Realistic human motion, natural body movement, joyful educational atmosphere.
16:9.
""",
2: """
Vietnamese middle school students walk together across the courtyard.
They laugh, talk and make friendly gestures.
Two students greet each other naturally.
Hands and arms move naturally while walking.
Other students continue walking in the background.
Smooth cinematic tracking camera.
Natural facial expressions and realistic body movement.
Keep the original characters and school environment consistent.
16:9.
""",
3: """
A Vietnamese teacher warmly greets students at the classroom door.
Students naturally stop and respectfully greet the teacher.
The teacher smiles and gently nods.
Students move their hands naturally.
Subtle classroom background movement.
Smooth cinematic camera movement toward the classroom.
Keep faces, uniforms and classroom unchanged.
Realistic human motion.
16:9.
""",
4: """
A Vietnamese middle school teacher explains a lesson.
Students actively participate and raise their hands.
Several students naturally move their hands and discuss ideas.
The teacher gestures naturally while explaining.
Students look at the teacher and classroom board.
Subtle camera movement from left to right.
Natural human movement and realistic facial expressions.
Keep the original classroom and characters consistent.
16:9.
""",
5: """
A student accidentally drops books and notebooks in the corridor.
Two classmates immediately walk toward the student and bend down.
They naturally pick up the books together.
The students smile and look at each other.
Books and hands move naturally.
Smooth cinematic camera tracking shot.
Warm emotional atmosphere.
Keep characters and school corridor consistent.
16:9.
""",
6: """
A student realizes a mistake in the classroom.
The student respectfully stands and apologizes to the teacher.
The teacher smiles kindly and gently encourages the student.
Classmates react positively and smile.
Natural gestures, head movement and facial expressions.
Slow cinematic camera movement.
Educational atmosphere about responsibility and correcting mistakes.
Keep the characters and classroom consistent.
16:9.
""",
7: """
Energetic Vietnamese middle school students perform a synchronized activity
in the school courtyard.
Students clap their hands and move rhythmically together.
Their arms and bodies move naturally to the music.
They smile confidently and enthusiastically.
Dynamic cinematic camera movement.
Youthful school music video atmosphere.
Keep the same students and uniforms consistent.
16:9.
""",
8: """
Students from different classes participate in a team-building activity.
They move together, cooperate and encourage one another.
Some students clap while others move through the activity.
Teachers observe and support the students.
Natural running, walking, hand and body movements.
Smooth cinematic camera tracking.
Joyful school community atmosphere.
Keep the school environment and characters consistent.
16:9.
""",
9: """
Wide aerial cinematic view of the school courtyard.
Many students and teachers participate in a joyful school activity.
Students naturally move and interact in organized groups.
Some students wave and raise their hands.
Trees gently move in the wind.
Slow cinematic aerial camera movement.
Warm sunlight and inspirational atmosphere.
Keep the school building and overall composition consistent.
16:9.
""",
10: """
Vietnamese middle school students stand together with their teachers.
Everyone smiles confidently toward the camera.
Students make subtle natural movements.
Teachers gently wave or nod.
Hair and clothing move slightly in the breeze.
Camera slowly moves backward from a close-up to a wide shot.
Emotional inspirational ending.
Keep all characters and the school building consistent.
Leave clean space for Vietnamese text.
16:9.
"""
}
==========================================
4. HÀM TẠO VIDEO
==========================================
def create_video(scene_number):
==========================================
5. TẠO TOÀN BỘ 10 CẢNH
==========================================
for scene in range(1, 11):
print()
print("=" * 60)
print("🎉 HOÀN THÀNH 10 CẢNH")
print("=" * 60)