shaheerawan3 commited on
Commit
d7b0d8c
·
verified ·
1 Parent(s): 1a68cc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -54
app.py CHANGED
@@ -327,75 +327,75 @@ class EnhancedVideoGenerator:
327
  self.logger.error(f"Voice-over generation failed: {str(e)}")
328
  return AudioFileClip(duration=len(script.split()) * 0.3)
329
 
330
- def create_video(self, script: str, style: str, duration: int, output_path: str, selected_images: List[str]) -> str:
331
- """Create video with selected images"""
332
- try:
333
- # Progress bar
334
- progress_bar = st.progress(0)
335
- status_text = st.empty()
336
-
337
- # Generate voice-over (20%)
338
- status_text.text("Creating voice-over...")
339
- audio = self.generate_voice_over(script)
340
- progress_bar.progress(20)
341
 
342
- # Process selected images (40%)
343
- status_text.text("Processing images...")
344
- processed_images = []
345
- for img_url in selected_images:
346
- response = requests.get(img_url)
347
- img = Image.open(BytesIO(response.content))
348
- img = img.resize((1920, 1080), Image.Resampling.LANCZOS)
349
- processed_images.append(np.array(img))
350
- progress_bar.progress(40)
 
 
 
 
 
351
 
352
- # Create frames with transitions
353
- fps = 30
354
- total_frames = int(duration * fps)
355
- frames = []
356
 
357
- status_text.text("Generating frames...")
358
- frames_per_image = total_frames // len(processed_images)
359
 
360
- for idx, img in enumerate(processed_images):
361
- for _ in range(frames_per_image):
362
- frames.append(img)
363
 
364
  # Add transition frames
365
- if idx < len(processed_images) - 1:
366
- next_img = processed_images[idx + 1]
367
- for alpha in np.linspace(0, 1, 15):
368
- transition_frame = (1 - alpha) * img + alpha * next_img
369
- frames.append(transition_frame.astype(np.uint8))
370
-
371
  progress_bar.progress(70)
372
 
373
  # Create video clip
374
- status_text.text("Compiling video...")
375
- video = ImageSequenceClip(frames, fps=fps)
376
- video = video.set_audio(audio)
377
 
378
- progress_bar.progress(90)
379
 
380
  # Write final video
381
- status_text.text("Saving video...")
382
- video.write_videofile(
383
- output_path,
384
- fps=fps,
385
- codec='libx264',
386
- audio_codec='aac',
387
- threads=4,
388
- preset='ultrafast'
389
- )
390
 
391
- progress_bar.progress(100)
392
- status_text.text("Video generation complete!")
393
 
394
- return output_path
395
 
396
- except Exception as e:
397
- self.logger.error(f"Video creation failed: {str(e)}")
398
- raise
399
 
400
 
401
  def generate_visual_assets(self, script: str, style: str) -> List[Dict]:
 
327
  self.logger.error(f"Voice-over generation failed: {str(e)}")
328
  return AudioFileClip(duration=len(script.split()) * 0.3)
329
 
330
+ def create_video(self, script: str, style: str, duration: int, output_path: str, selected_images: List[str]) -> str:
331
+ """Create video with selected images"""
332
+ try:
333
+ # Progress bar
334
+ progress_bar = st.progress(0)
335
+ status_text = st.empty()
 
 
 
 
 
336
 
337
+ # Generate voice-over (20%)
338
+ status_text.text("Creating voice-over...")
339
+ audio = self.generate_voice_over(script)
340
+ progress_bar.progress(20)
341
+
342
+ # Process selected images (40%)
343
+ status_text.text("Processing images...")
344
+ processed_images = []
345
+ for img_url in selected_images:
346
+ response = requests.get(img_url)
347
+ img = Image.open(BytesIO(response.content))
348
+ img = img.resize((1920, 1080), Image.Resampling.LANCZOS)
349
+ processed_images.append(np.array(img))
350
+ progress_bar.progress(40)
351
 
352
+ # Create frames with transitions
353
+ fps = 30
354
+ total_frames = int(duration * fps)
355
+ frames = []
356
 
357
+ status_text.text("Generating frames...")
358
+ frames_per_image = total_frames // len(processed_images)
359
 
360
+ for idx, img in enumerate(processed_images):
361
+ for _ in range(frames_per_image):
362
+ frames.append(img)
363
 
364
  # Add transition frames
365
+ if idx < len(processed_images) - 1:
366
+ next_img = processed_images[idx + 1]
367
+ for alpha in np.linspace(0, 1, 15):
368
+ transition_frame = (1 - alpha) * img + alpha * next_img
369
+ frames.append(transition_frame.astype(np.uint8))
370
+
371
  progress_bar.progress(70)
372
 
373
  # Create video clip
374
+ status_text.text("Compiling video...")
375
+ video = ImageSequenceClip(frames, fps=fps)
376
+ video = video.set_audio(audio)
377
 
378
+ progress_bar.progress(90)
379
 
380
  # Write final video
381
+ status_text.text("Saving video...")
382
+ video.write_videofile(
383
+ output_path,
384
+ fps=fps,
385
+ codec='libx264',
386
+ audio_codec='aac',
387
+ threads=4,
388
+ preset='ultrafast'
389
+ )
390
 
391
+ progress_bar.progress(100)
392
+ status_text.text("Video generation complete!")
393
 
394
+ return output_path
395
 
396
+ except Exception as e:
397
+ self.logger.error(f"Video creation failed: {str(e)}")
398
+ raise
399
 
400
 
401
  def generate_visual_assets(self, script: str, style: str) -> List[Dict]: