qqwjq1981 commited on
Commit
cb756d1
Β·
verified Β·
1 Parent(s): 11a89dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -20
app.py CHANGED
@@ -40,20 +40,15 @@ import wave
40
 
41
  logger = logging.getLogger(__name__)
42
 
 
 
 
 
 
43
  # Accept license terms for Coqui XTTS
44
  os.environ["COQUI_TOS_AGREED"] = "1"
45
  # torch.serialization.add_safe_globals([XttsConfig])
46
 
47
- # Load XTTS model
48
- try:
49
- print("πŸ”„ Loading XTTS model...")
50
- tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
51
- print("βœ… XTTS model loaded successfully.")
52
- except Exception as e:
53
- print("❌ Error loading XTTS model:")
54
- traceback.print_exc()
55
- raise e
56
-
57
  logger.info(gr.__version__)
58
 
59
  client = OpenAI(
@@ -61,7 +56,6 @@ client = OpenAI(
61
  )
62
  hf_api_key = os.environ.get("hf_token")
63
 
64
-
65
  def silence(duration, fps=44100):
66
  """
67
  Returns a silent AudioClip of the specified duration.
@@ -132,11 +126,6 @@ def handle_feedback(feedback):
132
  conn.commit()
133
  return "Thank you for your feedback!", None
134
 
135
- # Configure logging
136
- logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
137
- logger = logging.getLogger(__name__)
138
- logger.info(f"MoviePy Version: {moviepy.__version__}")
139
-
140
  # def segment_background_audio(audio_path, output_path="background_segments.wav"):
141
  # # Step 2: Initialize pyannote voice activity detection pipeline (you need Hugging Face token)
142
  # pipeline = Pipeline.from_pretrained(
@@ -490,9 +479,6 @@ def add_transcript_voiceover(video_path, translated_json, output_path, add_voice
490
 
491
  return error_messages
492
 
493
- # Initialize TTS model only once (outside the function)
494
- tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
495
-
496
  def generate_voiceover_clone(translated_json, desired_duration, target_language, speaker_wav_path, output_audio_path):
497
  try:
498
  full_text = " ".join(entry["translated"] for entry in translated_json if "translated" in entry and entry["translated"].strip())
@@ -677,6 +663,16 @@ def build_interface():
677
 
678
  return demo
679
 
 
 
 
 
 
 
 
 
 
 
680
  # Launch the Gradio interface
681
  demo = build_interface()
682
- demo.launch()
 
40
 
41
  logger = logging.getLogger(__name__)
42
 
43
+ # Configure logging
44
+ logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
45
+ logger = logging.getLogger(__name__)
46
+ logger.info(f"MoviePy Version: {moviepy.__version__}")
47
+
48
  # Accept license terms for Coqui XTTS
49
  os.environ["COQUI_TOS_AGREED"] = "1"
50
  # torch.serialization.add_safe_globals([XttsConfig])
51
 
 
 
 
 
 
 
 
 
 
 
52
  logger.info(gr.__version__)
53
 
54
  client = OpenAI(
 
56
  )
57
  hf_api_key = os.environ.get("hf_token")
58
 
 
59
  def silence(duration, fps=44100):
60
  """
61
  Returns a silent AudioClip of the specified duration.
 
126
  conn.commit()
127
  return "Thank you for your feedback!", None
128
 
 
 
 
 
 
129
  # def segment_background_audio(audio_path, output_path="background_segments.wav"):
130
  # # Step 2: Initialize pyannote voice activity detection pipeline (you need Hugging Face token)
131
  # pipeline = Pipeline.from_pretrained(
 
479
 
480
  return error_messages
481
 
 
 
 
482
  def generate_voiceover_clone(translated_json, desired_duration, target_language, speaker_wav_path, output_audio_path):
483
  try:
484
  full_text = " ".join(entry["translated"] for entry in translated_json if "translated" in entry and entry["translated"].strip())
 
663
 
664
  return demo
665
 
666
+ # Load XTTS model
667
+ try:
668
+ print("πŸ”„ Loading XTTS model...")
669
+ tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2")
670
+ print("βœ… XTTS model loaded successfully.")
671
+ except Exception as e:
672
+ print("❌ Error loading XTTS model:")
673
+ traceback.print_exc()
674
+ raise e
675
+
676
  # Launch the Gradio interface
677
  demo = build_interface()
678
+ demo.launch()