Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -376,49 +376,49 @@ class VideoGenerator:
|
|
| 376 |
return None
|
| 377 |
|
| 378 |
def create_video(self, content: Dict[str, str], preferences: Dict, style: ContentStyle) -> Optional[str]:
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
def main():
|
| 423 |
st.set_page_config(page_title="Professional Content Generator", layout="wide")
|
| 424 |
|
|
|
|
| 376 |
return None
|
| 377 |
|
| 378 |
def create_video(self, content: Dict[str, str], preferences: Dict, style: ContentStyle) -> Optional[str]:
|
| 379 |
+
"""Create video with PIL-based text rendering and proper MoviePy conversion"""
|
| 380 |
+
try:
|
| 381 |
+
self.update_progress(85, "Creating video...")
|
| 382 |
+
|
| 383 |
+
# Create frames directory
|
| 384 |
+
frames_dir = os.path.join(self.temp_dir, "frames")
|
| 385 |
+
os.makedirs(frames_dir, exist_ok=True)
|
| 386 |
+
|
| 387 |
+
# Create main content frame
|
| 388 |
+
frame = self.create_text_image(content['main_content'][:200])
|
| 389 |
+
|
| 390 |
+
# Save frame as image
|
| 391 |
+
frame_path = os.path.join(frames_dir, "frame.png")
|
| 392 |
+
Image.fromarray(frame).save(frame_path)
|
| 393 |
+
|
| 394 |
+
# Create video from frame
|
| 395 |
+
output_path = os.path.join(self.temp_dir, f"output_{int(time.time())}.mp4")
|
| 396 |
+
|
| 397 |
+
# Create video clip from image (not video file)
|
| 398 |
+
# Use ImageClip instead of VideoFileClip for static images
|
| 399 |
+
from moviepy.editor import ImageClip
|
| 400 |
+
clip = ImageClip(frame_path).set_duration(15) # 15 seconds duration
|
| 401 |
+
|
| 402 |
+
# Write video file
|
| 403 |
+
self.update_progress(95, "Saving video...")
|
| 404 |
+
clip.write_videofile(output_path, fps=24, codec='libx264', audio=False)
|
| 405 |
+
|
| 406 |
+
# Cleanup
|
| 407 |
+
clip.close()
|
| 408 |
+
if os.path.exists(frame_path):
|
| 409 |
+
os.remove(frame_path)
|
| 410 |
+
|
| 411 |
+
return output_path
|
| 412 |
+
|
| 413 |
+
except Exception as e:
|
| 414 |
+
st.error(f"Error creating video: {str(e)}")
|
| 415 |
+
return None
|
| 416 |
+
finally:
|
| 417 |
+
# Cleanup frames directory
|
| 418 |
+
if os.path.exists(frames_dir):
|
| 419 |
+
import shutil
|
| 420 |
+
shutil.rmtree(frames_dir)
|
| 421 |
+
|
| 422 |
def main():
|
| 423 |
st.set_page_config(page_title="Professional Content Generator", layout="wide")
|
| 424 |
|