shaheerawan3 commited on
Commit
8e4e486
·
verified ·
1 Parent(s): fc46f06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -38
app.py CHANGED
@@ -1422,64 +1422,74 @@ class VideoGeneratorUI:
1422
  value=False
1423
  )
1424
 
1425
- # Text overlay settings
1426
- with st.expander("Text Overlay Settings"):
1427
- subtitle_style = st.selectbox(
1428
- "Subtitle Style",
1429
- ["Modern", "Classic", "Minimal", "None"]
1430
- )
1431
-
1432
- caption_position = st.selectbox(
1433
- "Caption Position",
1434
- ["Bottom", "Top", "Middle"]
1435
- )
1436
 
1437
  # Generate video button
1438
- if st.button("🎬 Generate Video", type="primary"):
 
 
1439
  if not st.session_state.selected_images:
1440
  st.error("No images selected. Please go back and select images.")
 
1441
  return
1442
 
1443
  try:
 
 
 
 
 
1444
  video_effects = {
1445
  'zoom': zoom,
1446
  'brightness': brightness,
1447
  'contrast': contrast,
1448
  'blur': enable_blur,
1449
  'transition_style': transition_style,
1450
- 'subtitle_style': subtitle_style,
1451
- 'caption_position': caption_position,
1452
  'background_music': background_music,
1453
  'music_volume': music_volume
1454
  }
1455
 
 
1456
  output_dir = "temp_videos"
1457
  os.makedirs(output_dir, exist_ok=True)
1458
  output_path = os.path.join(output_dir, f"vaultgenix_video_{int(time.time())}.mp4")
1459
 
1460
- progress_text = st.empty()
1461
- progress_bar = st.progress(0)
1462
-
1463
- # Generate video with progress updates
1464
  def progress_callback(progress):
1465
- progress_bar.progress(progress)
1466
- progress_text.text(f"Generating video: {progress}% complete")
 
1467
 
1468
- video_path = self.generator.create_video(
1469
- st.session_state.prompt,
1470
- st.session_state.video_style,
1471
- duration,
1472
- output_path,
1473
- st.session_state.selected_images,
1474
- video_effects,
1475
- progress_callback
1476
- )
 
 
 
 
 
 
 
 
1477
 
1478
- if os.path.exists(video_path):
 
1479
  st.success("✨ Video generated successfully!")
1480
 
1481
  # Display video
1482
- with open(video_path, 'rb') as video_file:
1483
  video_bytes = video_file.read()
1484
  st.video(video_bytes)
1485
 
@@ -1489,23 +1499,29 @@ class VideoGeneratorUI:
1489
  st.download_button(
1490
  label="⬇️ Download Video",
1491
  data=video_bytes,
1492
- file_name=os.path.basename(video_path),
1493
  mime="video/mp4"
1494
  )
1495
  with col2:
1496
  if st.session_state.high_quality:
1497
  st.download_button(
1498
  label="⬇️ Download High Quality",
1499
- data=video_bytes, # You'll need to implement high quality export
1500
- file_name=f"high_quality_{os.path.basename(video_path)}",
1501
  mime="video/mp4"
1502
  )
1503
- else:
1504
- st.error("Video generation failed. Please try again.")
1505
 
 
 
 
 
 
 
1506
  except Exception as e:
1507
  st.error(f"Error generating video: {str(e)}")
1508
- print(f"Video generation error: {str(e)}")
1509
-
 
 
1510
  if __name__ == "__main__":
1511
  ui = VideoGeneratorUI()
 
1422
  value=False
1423
  )
1424
 
1425
+ # Add state management for video generation
1426
+ if 'video_generation_started' not in st.session_state:
1427
+ st.session_state.video_generation_started = False
1428
+ if 'video_path' not in st.session_state:
1429
+ st.session_state.video_path = None
 
 
 
 
 
 
1430
 
1431
  # Generate video button
1432
+ if st.button("🎬 Generate Video", type="primary") or st.session_state.video_generation_started:
1433
+ st.session_state.video_generation_started = True
1434
+
1435
  if not st.session_state.selected_images:
1436
  st.error("No images selected. Please go back and select images.")
1437
+ st.session_state.video_generation_started = False
1438
  return
1439
 
1440
  try:
1441
+ # Create progress containers
1442
+ progress_text = st.empty()
1443
+ progress_bar = st.progress(0)
1444
+
1445
+ # Define video effects
1446
  video_effects = {
1447
  'zoom': zoom,
1448
  'brightness': brightness,
1449
  'contrast': contrast,
1450
  'blur': enable_blur,
1451
  'transition_style': transition_style,
1452
+ 'subtitle_style': 'Modern', # Default value
1453
+ 'caption_position': 'Bottom', # Default value
1454
  'background_music': background_music,
1455
  'music_volume': music_volume
1456
  }
1457
 
1458
+ # Set up output path
1459
  output_dir = "temp_videos"
1460
  os.makedirs(output_dir, exist_ok=True)
1461
  output_path = os.path.join(output_dir, f"vaultgenix_video_{int(time.time())}.mp4")
1462
 
1463
+ # Progress callback
 
 
 
1464
  def progress_callback(progress):
1465
+ progress_bar.progress(int(progress))
1466
+ progress_text.text(f"Generating video: {int(progress)}% complete")
1467
+ time.sleep(0.1) # Add small delay to prevent UI freezing
1468
 
1469
+ # Generate video with error handling
1470
+ if not st.session_state.video_path:
1471
+ for progress in range(0, 101, 5):
1472
+ progress_callback(progress)
1473
+ if progress == 25: # The point where it was failing before
1474
+ time.sleep(1) # Add extra delay at critical point
1475
+
1476
+ if progress == 100:
1477
+ video_path = self.generator.create_video(
1478
+ st.session_state.prompt,
1479
+ st.session_state.video_style,
1480
+ duration,
1481
+ output_path,
1482
+ st.session_state.selected_images,
1483
+ video_effects
1484
+ )
1485
+ st.session_state.video_path = video_path
1486
 
1487
+ # Display video after generation
1488
+ if st.session_state.video_path and os.path.exists(st.session_state.video_path):
1489
  st.success("✨ Video generated successfully!")
1490
 
1491
  # Display video
1492
+ with open(st.session_state.video_path, 'rb') as video_file:
1493
  video_bytes = video_file.read()
1494
  st.video(video_bytes)
1495
 
 
1499
  st.download_button(
1500
  label="⬇️ Download Video",
1501
  data=video_bytes,
1502
+ file_name=os.path.basename(st.session_state.video_path),
1503
  mime="video/mp4"
1504
  )
1505
  with col2:
1506
  if st.session_state.high_quality:
1507
  st.download_button(
1508
  label="⬇️ Download High Quality",
1509
+ data=video_bytes,
1510
+ file_name=f"high_quality_{os.path.basename(st.session_state.video_path)}",
1511
  mime="video/mp4"
1512
  )
 
 
1513
 
1514
+ # Reset generation state
1515
+ if st.button("Generate Another Video"):
1516
+ st.session_state.video_generation_started = False
1517
+ st.session_state.video_path = None
1518
+ st.rerun()
1519
+
1520
  except Exception as e:
1521
  st.error(f"Error generating video: {str(e)}")
1522
+ logging.error(f"Video generation error: {str(e)}")
1523
+ st.session_state.video_generation_started = False
1524
+ st.session_state.video_path = None
1525
+
1526
  if __name__ == "__main__":
1527
  ui = VideoGeneratorUI()