Coco-18 commited on
Commit
b9d1c73
Β·
verified Β·
1 Parent(s): 91e93fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -169,7 +169,7 @@ for model_key, model_id in TRANSLATION_MODELS.items():
169
  # Constants
170
  SAMPLE_RATE = 16000
171
  OUTPUT_DIR = "/tmp/audio_outputs"
172
- REPO_REFERENCE_DIR = "./reference_audio"
173
 
174
  try:
175
  os.makedirs(OUTPUT_DIR, exist_ok=True)
@@ -744,22 +744,25 @@ def upload_reference_audio():
744
 
745
  def init_reference_audio():
746
  try:
747
- os.makedirs(REFERENCE_AUDIO_DIR, exist_ok=True)
748
- logger.info(f"πŸ“ Created reference audio directory: {REFERENCE_AUDIO_DIR}")
 
749
 
750
- # Copy reference files from repository to runtime directory
751
- if os.path.exists(REPO_REFERENCE_DIR):
752
- for pattern_dir in os.listdir(REPO_REFERENCE_DIR):
753
- src_dir = os.path.join(REPO_REFERENCE_DIR, pattern_dir)
754
- if os.path.isdir(src_dir):
755
- dst_dir = os.path.join(REFERENCE_AUDIO_DIR, pattern_dir)
756
- os.makedirs(dst_dir, exist_ok=True)
757
-
758
- # Copy all wav files
759
- for wav_file in glob.glob(os.path.join(src_dir, "*.wav")):
760
- shutil.copy(wav_file, dst_dir)
761
-
762
- logger.info(f"πŸ“ Copied reference files from repository")
 
 
763
  except Exception as e:
764
  logger.error(f"❌ Failed to set up reference audio directory: {str(e)}")
765
 
 
169
  # Constants
170
  SAMPLE_RATE = 16000
171
  OUTPUT_DIR = "/tmp/audio_outputs"
172
+ REFERENCE_AUDIO_DIR = "./reference_audios"
173
 
174
  try:
175
  os.makedirs(OUTPUT_DIR, exist_ok=True)
 
744
 
745
  def init_reference_audio():
746
  try:
747
+ # Create the output directory first
748
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
749
+ logger.info(f"πŸ“ Created output directory: {OUTPUT_DIR}")
750
 
751
+ # Check if the reference audio directory exists in the repository
752
+ if os.path.exists(REFERENCE_AUDIO_DIR):
753
+ logger.info(f"βœ… Found reference audio directory: {REFERENCE_AUDIO_DIR}")
754
+
755
+ # Log the contents to verify
756
+ pattern_dir = os.path.join(REFERENCE_AUDIO_DIR, reference_word)
757
+ if not os.path.exists(pattern_dir):
758
+ logger.warning(f"⚠️ Cannot write to repository directory: {pattern_dir}")
759
+ # Create a temporary directory instead
760
+ temp_dir = os.path.join(OUTPUT_DIR, "references", reference_word)
761
+ os.makedirs(temp_dir, exist_ok=True)
762
+ pattern_dir = temp_dir
763
+ logger.info(f"πŸ“ Created temporary reference directory: {pattern_dir}")
764
+ else:
765
+ logger.warning(f"⚠️ Reference audio directory not found: {REFERENCE_AUDIO_DIR}")
766
  except Exception as e:
767
  logger.error(f"❌ Failed to set up reference audio directory: {str(e)}")
768