Update generate.py
Browse files- generate.py +15 -2
generate.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
|
|
|
| 3 |
import textwrap
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image, ImageDraw, ImageFont
|
|
@@ -35,18 +36,30 @@ def make_text_frame(text):
|
|
| 35 |
|
| 36 |
def generate_video(script, title, description):
|
| 37 |
print("Starting video generation...")
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
sentences = sentences[:15]
|
|
|
|
|
|
|
| 40 |
clips = []
|
| 41 |
for i, sentence in enumerate(sentences):
|
| 42 |
-
print(f"Creating clip {i+1}/{len(sentences)}")
|
| 43 |
frame = make_text_frame(sentence)
|
| 44 |
clip = ImageClip(frame, duration=DURATION_PER_LINE)
|
| 45 |
clip = clip.fadein(0.3).fadeout(0.3)
|
| 46 |
clips.append(clip)
|
|
|
|
| 47 |
if not clips:
|
| 48 |
print("No clips generated!")
|
| 49 |
return False
|
|
|
|
| 50 |
print("Combining clips...")
|
| 51 |
final = concatenate_videoclips(clips, method="compose")
|
| 52 |
output_path = '/app/video.mp4'
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
+
import re
|
| 4 |
import textwrap
|
| 5 |
import numpy as np
|
| 6 |
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
| 36 |
|
| 37 |
def generate_video(script, title, description):
|
| 38 |
print("Starting video generation...")
|
| 39 |
+
print(f"Script received: {script[:100]}")
|
| 40 |
+
|
| 41 |
+
sentences = re.split(r'[.!?\n]', script)
|
| 42 |
+
sentences = [s.strip() for s in sentences if len(s.strip()) > 5]
|
| 43 |
+
|
| 44 |
+
if not sentences:
|
| 45 |
+
words = script.split()
|
| 46 |
+
sentences = [' '.join(words[i:i+8]) for i in range(0, len(words), 8)]
|
| 47 |
+
|
| 48 |
sentences = sentences[:15]
|
| 49 |
+
print(f"Total clips to generate: {len(sentences)}")
|
| 50 |
+
|
| 51 |
clips = []
|
| 52 |
for i, sentence in enumerate(sentences):
|
| 53 |
+
print(f"Creating clip {i+1}/{len(sentences)}: {sentence[:30]}")
|
| 54 |
frame = make_text_frame(sentence)
|
| 55 |
clip = ImageClip(frame, duration=DURATION_PER_LINE)
|
| 56 |
clip = clip.fadein(0.3).fadeout(0.3)
|
| 57 |
clips.append(clip)
|
| 58 |
+
|
| 59 |
if not clips:
|
| 60 |
print("No clips generated!")
|
| 61 |
return False
|
| 62 |
+
|
| 63 |
print("Combining clips...")
|
| 64 |
final = concatenate_videoclips(clips, method="compose")
|
| 65 |
output_path = '/app/video.mp4'
|