Spaces:
Sleeping
Sleeping
Update app.py
Browse files10 unmodified lines11121314151617181934 unmodified lines5455565758596010 unmodified lines71727374757611 unmodified lines8889909192939495969798991001011028 unmodified lines11111211311411511611711811910 unmodified linesfrom src.audio_preprocessing import assess_pronunciation_qualityfrom datetime import datetimefrom pathlib import Path@spaces.GPUdef check_pronunciation(reference_audio, input_audio, threshold, wavlm_layer):wavlm_layer = int(wavlm_layer)timing_results = []34 unmodified linesraise ValueError("DTW computation failed.")PronunciationChecker.plot_waveform_with_overlay(ref_wav, sr, dist_matrix, path, "ref", threshold)log_timing("Visualization Generation")# Save the visualization to a temporary image file10 unmodified lines# Return the image file path for Gradio to displayreturn tmp_path, quality_score, needs_repeat, timing_analysis@spaces.GPUdef run_tests(threshold=0.4, wavlm_layer=24):# Create a directory for storing plots if it doesn't exist11 unmodified linesif test_word_dir.is_dir():word = test_word_dir.nameref_file = test_word_dir / "ref.wav"if not ref_file.exists():test_cases.append({"heading": f"Error: Missing reference file for '{word}'","plot": None,"text": f"Reference file not found for test word '{word}'."})continuefor input_file in test_word_dir.glob("input_*.wav"):if not input_file.exists():test_cases.append({8 unmodified linesplot_filename = f"{word}_{input_file.stem}_{datetime.now().strftime('%H%M%S')}.png"plot_path = plots_dir / plot_filename# Run the pronunciation checkertmp_path, quality_score, needs_repeat, timing_analysis = check_pronunciation(ref_file, input_file, threshold, wavlm_layer)# Move the plot to our persistent directory10 unmodified lines1112131415161718192034 unmodified lines5556575859606110 unmodified lines7273747576777879808182838485868788899011 unmodified lines1021031041051061071081091101111121131141151161171181198 unmodified lines12812913013113213313413513613713813910 unmodified linesfrom src.audio_preprocessing import assess_pronunciation_qualityfrom datetime import datetimefrom pathlib import Pathimport re@spaces.GPUdef check_pronunciation(reference_audio, input_audio, threshold, wavlm_layer, labels_data=None, input_number=None):wavlm_layer = int(wavlm_layer)timing_results = []34 unmodified linesraise ValueError("DTW computation failed.")PronunciationChecker.plot_waveform_with_overlay(ref_wav, sr, dist_matrix, path, "ref", threshold, labels_data, input_number)log_timing("Visualization Generation")# Save the visualization to a temporary image file10 unmodified lines# Return the image file path for Gradio to displayreturn tmp_path, quality_score, needs_repeat, timing_analysisdef parse_labels_file(labels_file):labels_data = []with open(labels_file, 'r') as f:for line in f:parts = re.split(r'[\t ]+', line)if len(parts) < 3:continuestart, end = map(float, parts[:2])grapheme = parts[2]boolean_labels = list(map(int, parts[3:]))labels_data.append((start, end, grapheme, *boolean_labels))return labels_data@spaces.GPUdef run_tests(threshold=0.4, wavlm_layer=24):# Create a directory for storing plots if it doesn't exist11 unmodified linesif test_word_dir.is_dir():word = test_word_dir.nameref_file = test_word_dir / "ref.wav"labels_file = test_word_dir / "labels.txt"if not ref_file.exists() or not labels_file.exists():test_cases.append({"heading": f"Error: Missing files for '{word}'","plot": None,"text": f"Missing required files (ref.wav or labels.txt) for test word '{word}'."})continuelabels_data = parse_labels_file(labels_file)for input_file in test_word_dir.glob("input_*.wav"):if not input_file.exists():test_cases.append({8 unmodified linesplot_filename = f"{word}_{input_file.stem}_{datetime.now().strftime('%H%M%S')}.png"plot_path = plots_dir / plot_filenameinput_number = str(input_file.stem).split('_')[1]input_number = int(input_number)-1# Run the pronunciation checkertmp_path, quality_score, needs_repeat, timing_analysis = check_pronunciation(ref_file, input_file, threshold, wavlm_layer, labels_data, input_number)# Move the plot to our persistent directory
app.py+26-6