Spaces:
Sleeping
Sleeping
Download scripts/predict_runner.py from krislette/bach-or-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/krislette/bach-or-bot/resolve/main/scripts/predict_runner.py
- Command line
-
hf download hf://spaces/krislette/bach-or-bot/scripts/predict_runner.py
-
curl -L -o predict_runner.py https://huggingface.co/spaces/krislette/bach-or-bot/resolve/main/scripts/predict_runner.py
1.19 kB
| import librosa | |
| from scripts.predict import predict_multimodal, predict_unimodal | |
| def predict_multimodal_runner(sample: str): | |
| # Load test audio and lyrics | |
| audio_path = f"data/external/{sample}.mp3" | |
| lyrics_path = f"data/external/{sample}.txt" | |
| # Load audio | |
| audio_data, sr = librosa.load(audio_path) | |
| # Load lyrics | |
| with open(lyrics_path, "r", encoding="utf-8") as f: | |
| lyrics_text = f.read() | |
| print("Running multimodal prediction pipeline...") | |
| prediction = predict_multimodal(audio_data, lyrics_text) | |
| print("\n=== MULTIMODAL PREDICTION RESULT ===") | |
| print(f"Prediction: {prediction}") | |
| def predict_unimodal_runner(sample: str): | |
| # Load test audio | |
| audio_path = f"data/external/{sample}.mp3" | |
| # Load audio | |
| audio_data, sr = librosa.load(audio_path) | |
| print("Running audio-only prediction pipeline...") | |
| prediction = predict_unimodal(audio_data) | |
| print("\n=== AUDIO-ONLY PREDICTION RESULT ===") | |
| print(f"Prediction: {prediction}") | |
| if __name__ == "__main__": | |
| sample = "sample" | |
| # Run both predictions | |
| predict_multimodal_runner(sample) | |
| print("\n" + "=" * 50 + "\n") | |
| predict_unimodal_runner(sample) | |