gholapeajinkya commited on
Commit
28ebbd3
Β·
verified Β·
1 Parent(s): f01142b

UI layout updated

Browse files
Files changed (1) hide show
  1. app.py +38 -53
app.py CHANGED
@@ -316,7 +316,6 @@ def voice_cloning(segments, audio_path, max_threads=2):
316
 
317
  def set_processing(value=True):
318
  st.session_state.is_processing = value
319
-
320
  if __name__ == "__main__":
321
  if "is_processing" not in st.session_state:
322
  st.session_state.is_processing = False
@@ -419,10 +418,10 @@ if __name__ == "__main__":
419
  if video_file is not None:
420
  st.session_state.is_processing = True
421
  start_time = time.time()
422
- input_col1, input_col2 = st.columns(2)
423
  st.divider()
424
- output_col1, output_col2 = st.columns(2)
425
- with input_col1:
426
  st.video(video_file, muted=False)
427
  uploaded_video_path = os.path.join(temp_folder, "uploaded_video.mp4")
428
  if not os.path.exists(uploaded_video_path):
@@ -433,7 +432,7 @@ if __name__ == "__main__":
433
  audio_path = extract_audio_from_video(uploaded_video_path)
434
 
435
  # Run Demucs to separate background audio
436
- with input_col2:
437
  output_dir = separate_audio_layers(audio_path)
438
 
439
  # Display the separated audio files
@@ -443,46 +442,31 @@ if __name__ == "__main__":
443
  bg_music_path = os.path.join(separated_dir, "other.wav")
444
  bass_path = os.path.join(separated_dir, "bass.wav")
445
  drums_path = os.path.join(separated_dir, "drums.wav")
446
- with input_col2:
447
- if os.path.exists(vocals_path) and os.path.exists(bg_music_path) and os.path.exists(bass_path) and os.path.exists(drums_path):
448
- col1, col2 = st.columns(2)
449
- with col1:
450
- st.write("🎀 Vocals: ")
451
- st.audio(vocals_path)
452
- st.write("🎡 Background Music: ")
453
- st.audio(bg_music_path)
454
- with col2:
455
- st.write("πŸ₯ Drums: ")
456
- st.audio(drums_path)
457
- st.write("🎸 Bass: ")
458
- st.audio(bass_path)
459
- else:
460
- st.error("Audio separation failed. Please check the logs.")
461
-
462
- segments = transcribe_audio(vocals_path)
463
- # Translate the segments using AI
464
- segments = translate_with_gpt(segments)
465
- with output_col2:
466
- filtered_segments = [
467
- {
468
- "id": s.get("id"),
469
- "start (sec)": s.get("start"),
470
- "end (sec)": s.get("end"),
471
- "duration (sec)": (s.get("end") - s.get("start")),
472
- "translation": s.get("translation"),
473
- "text": s.get("text"),
474
- "speech_prob": f"{round(round(s.get('no_speech_prob', 0), 2) * 100, 2)}%",
475
- "avg_logprob": s.get("avg_logprob", 0),
476
- }
477
- for s in segments
478
- ]
479
- df = pd.DataFrame(filtered_segments)
480
- st.data_editor(df, use_container_width=True,
481
- hide_index=True, num_rows="dynamic", disabled=True)
482
- segments_csv_path = os.path.join(
483
- sample_output_dir, f"output_segments_{selected_model}_{output_language.lower()}.csv")
484
- df.to_csv(segments_csv_path, index=False, encoding="utf-8")
485
- with output_col1:
486
  voice_cloning(segments, vocals_path)
487
 
488
  translated_audio = generate_audio_from_segments(segments, audio_path)
@@ -492,17 +476,18 @@ if __name__ == "__main__":
492
  bg_audio = AudioFileClip(bg_music_path)
493
  drums_audio = AudioFileClip(drums_path)
494
  bass_audio = AudioFileClip(bass_path)
495
- with output_col1:
496
  with st.spinner("🎬 Generating dubbed video..."):
497
- # Combine audio tracks
498
  combined_audio = CompositeAudioClip(
499
  [translated_audio, bg_audio, drums_audio, bass_audio])
500
-
501
  video = video.with_audio(combined_audio)
502
  dubbed_video_path = os.path.join(
503
  sample_output_dir, f"dubbed_video_{selected_model}_{output_language.lower()}.mp4")
504
  video.write_videofile(
505
  dubbed_video_path, codec="libx264", audio_codec="aac")
 
506
  st.video(dubbed_video_path)
507
  end_time = time.time()
508
  # # Calculate the elapsed time
@@ -518,7 +503,7 @@ if __name__ == "__main__":
518
  st.markdown("""
519
  Welcome to DubSync! Transform your videos with AI-powered dubbing that preserves voice characteristics and emotions.
520
 
521
- πŸ“– **[Read the Complete Documentation & Setup Guide](https://github.com/gholapeajinkya/DubSync/blob/main/README.md)** - Learn about features, installation, requirements, and how it works.
522
  """)
523
 
524
  st.subheader("πŸ“Ί Demo Videos")
@@ -541,7 +526,7 @@ if __name__ == "__main__":
541
  else:
542
  with demo_cols[i]:
543
  st.markdown(f"**{title}**")
544
- st.info("Demo video will appear here")
545
 
546
  st.markdown("---")
547
 
@@ -550,7 +535,7 @@ if __name__ == "__main__":
550
  try:
551
  sample_df = pd.read_csv(os.path.join(
552
  demo_dir, "output_segments_large_english.csv"))
553
- st.dataframe(sample_df.head(10), use_container_width=True, hide_index=True)
 
554
  except Exception as e:
555
- st.info(
556
- "Sample transcription data will appear here")
 
316
 
317
  def set_processing(value=True):
318
  st.session_state.is_processing = value
 
319
  if __name__ == "__main__":
320
  if "is_processing" not in st.session_state:
321
  st.session_state.is_processing = False
 
418
  if video_file is not None:
419
  st.session_state.is_processing = True
420
  start_time = time.time()
421
+ input_video_col, output_video_col = st.columns(2)
422
  st.divider()
423
+ with input_video_col:
424
+ st.subheader("Input Video")
425
  st.video(video_file, muted=False)
426
  uploaded_video_path = os.path.join(temp_folder, "uploaded_video.mp4")
427
  if not os.path.exists(uploaded_video_path):
 
432
  audio_path = extract_audio_from_video(uploaded_video_path)
433
 
434
  # Run Demucs to separate background audio
435
+ with output_video_col:
436
  output_dir = separate_audio_layers(audio_path)
437
 
438
  # Display the separated audio files
 
442
  bg_music_path = os.path.join(separated_dir, "other.wav")
443
  bass_path = os.path.join(separated_dir, "bass.wav")
444
  drums_path = os.path.join(separated_dir, "drums.wav")
445
+ with output_video_col:
446
+ segments = transcribe_audio(vocals_path)
447
+ with output_video_col:
448
+ # Translate the segments using AI
449
+ segments = translate_with_gpt(segments)
450
+ filtered_segments = [
451
+ {
452
+ "id": s.get("id"),
453
+ "start (sec)": s.get("start"),
454
+ "end (sec)": s.get("end"),
455
+ "translation": s.get("translation"),
456
+ "text": s.get("text"),
457
+ "no_speech_prob": s.get('no_speech_prob', 0),
458
+ "avg_logprob": s.get("avg_logprob", 0),
459
+ }
460
+ for s in segments
461
+ ]
462
+ df = pd.DataFrame(filtered_segments)
463
+ st.subheader("Transcription")
464
+ st.data_editor(df, use_container_width=True,
465
+ hide_index=True, num_rows="dynamic", disabled=True)
466
+ segments_csv_path = os.path.join(
467
+ sample_output_dir, f"output_segments_{selected_model}_{output_language.lower()}.csv")
468
+ df.to_csv(segments_csv_path, index=False, encoding="utf-8")
469
+ with output_video_col:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  voice_cloning(segments, vocals_path)
471
 
472
  translated_audio = generate_audio_from_segments(segments, audio_path)
 
476
  bg_audio = AudioFileClip(bg_music_path)
477
  drums_audio = AudioFileClip(drums_path)
478
  bass_audio = AudioFileClip(bass_path)
479
+ with output_video_col:
480
  with st.spinner("🎬 Generating dubbed video..."):
481
+ # Combine audio tracks
482
  combined_audio = CompositeAudioClip(
483
  [translated_audio, bg_audio, drums_audio, bass_audio])
484
+
485
  video = video.with_audio(combined_audio)
486
  dubbed_video_path = os.path.join(
487
  sample_output_dir, f"dubbed_video_{selected_model}_{output_language.lower()}.mp4")
488
  video.write_videofile(
489
  dubbed_video_path, codec="libx264", audio_codec="aac")
490
+ st.subheader("Dubbed video")
491
  st.video(dubbed_video_path)
492
  end_time = time.time()
493
  # # Calculate the elapsed time
 
503
  st.markdown("""
504
  Welcome to DubSync! Transform your videos with AI-powered dubbing that preserves voice characteristics and emotions.
505
 
506
+ πŸ“– **[Read the Complete Documentation & Setup Guide](https://github.com/gholapeajinkya/DubSync/blob/main/README.md#dubsync)** - Learn about features, installation, requirements, and how it works.
507
  """)
508
 
509
  st.subheader("πŸ“Ί Demo Videos")
 
526
  else:
527
  with demo_cols[i]:
528
  st.markdown(f"**{title}**")
529
+ st.info("Demo video will appear")
530
 
531
  st.markdown("---")
532
 
 
535
  try:
536
  sample_df = pd.read_csv(os.path.join(
537
  demo_dir, "output_segments_large_english.csv"))
538
+ st.dataframe(sample_df.head(
539
+ 10), use_container_width=True, hide_index=True)
540
  except Exception as e:
541
+ st.info("Sample transcription data will appear here")