meity / test_notebook_processing.py
Themozhi's picture
Upload folder using huggingface_hub
426f1f2 verified
Raw History Blame Contribute Delete
9.97 kB
#!/usr/bin/env python3
"""
Standalone test script to debug notebook processing issues.
Run this to identify what's failing in your setup.
"""
import os
import sys
import subprocess
import traceback
def test_dependencies():
"""Test if all required dependencies are installed."""
print("πŸ” TESTING DEPENDENCIES")
print("=" * 50)
# Test Python packages
packages = [
'gradio', 'torch', 'torchaudio', 'numpy',
'soundfile', 'librosa', 'nbconvert', 'nbformat', 'jupyter'
]
for package in packages:
try:
__import__(package)
print(f"βœ… {package}")
except ImportError:
print(f"❌ {package} - Install with: pip install {package}")
# Test Jupyter command
try:
result = subprocess.run(['jupyter', '--version'], capture_output=True, text=True, timeout=10)
if result.returncode == 0:
print("βœ… jupyter command available")
else:
print("❌ jupyter command failed")
except Exception as e:
print(f"❌ jupyter command error: {e}")
# Test PyTorch GPU
try:
import torch
print(f"βœ… PyTorch {torch.__version__}")
print(f" CUDA available: {torch.cuda.is_available()}")
if torch.cuda.is_available():
print(f" GPU: {torch.cuda.get_device_name()}")
except:
print("❌ PyTorch not working")
def test_file_paths():
"""Test if required files and directories exist."""
print("\nπŸ” TESTING FILE PATHS")
print("=" * 50)
paths_to_check = [
r"C:\Users\beyon\Downloads\meity",
r"C:\Users\beyon\Downloads\meity\dysarthric_demo.py",
r"C:\Users\beyon\Downloads\meity\notebook_processor.py",
r"C:\Users\beyon\Downloads\meity\audio_processor.py",
r"C:\Users\beyon\Downloads\fyp-demo",
r"C:\Users\beyon\Downloads\meity-demo.ipynb",
r"C:\Users\beyon\Downloads\LJ001-0005.wav"
]
for path in paths_to_check:
if os.path.exists(path):
print(f"βœ… {path}")
else:
print(f"❌ {path}")
def test_audio_processor():
"""Test the standalone audio processor script."""
print("\nπŸ” TESTING AUDIO PROCESSOR")
print("=" * 50)
script_path = r"C:\Users\beyon\Downloads\meity\audio_processor.py"
test_input = r"C:\Users\beyon\Downloads\LJ001-0005.wav"
test_output = r"C:\Users\beyon\Downloads\meity\temp_outputs\test_output.wav"
if not os.path.exists(script_path):
print(f"❌ Audio processor script not found: {script_path}")
return
if not os.path.exists(test_input):
print(f"❌ Test input file not found: {test_input}")
return
# Create output directory
os.makedirs(os.path.dirname(test_output), exist_ok=True)
try:
print(f"Running: python {script_path} --input {test_input} --output {test_output}")
result = subprocess.run([
sys.executable, script_path,
'--input', test_input,
'--output', test_output,
'--verbose'
], capture_output=True, text=True, timeout=120)
print(f"Return code: {result.returncode}")
print(f"STDOUT:\n{result.stdout}")
print(f"STDERR:\n{result.stderr}")
if os.path.exists(test_output):
print(f"βœ… Output file created: {test_output}")
else:
print(f"❌ Output file not created")
except subprocess.TimeoutExpired:
print("❌ Audio processor timeout (>2 minutes)")
except Exception as e:
print(f"❌ Error running audio processor: {e}")
def test_notebook_execution():
"""Test notebook execution directly."""
print("\nπŸ” TESTING NOTEBOOK EXECUTION")
print("=" * 50)
notebook_path = r"C:\Users\beyon\Downloads\meity-demo.ipynb"
if not os.path.exists(notebook_path):
print(f"❌ Notebook not found: {notebook_path}")
return
# Test nbconvert
try:
result = subprocess.run([
'jupyter', 'nbconvert', '--help'
], capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print("βœ… nbconvert available")
else:
print("❌ nbconvert failed")
print(f"Error: {result.stderr}")
except Exception as e:
print(f"❌ nbconvert error: {e}")
def test_torch_hub():
"""Test if torch.hub model downloads work."""
print("\nπŸ” TESTING TORCH HUB MODEL DOWNLOADS")
print("=" * 50)
try:
import torch
print("Testing model downloads (this may take a few minutes)...")
# Test HuBERT download
print("Downloading HuBERT model...")
hubert = torch.hub.load("Themozhi/hubert:main", "hubert_soft", trust_repo=True)
print("βœ… HuBERT model downloaded successfully")
# Test device placement
device = "cuda" if torch.cuda.is_available() else "cpu"
if device == "cuda":
hubert = hubert.cuda()
print("βœ… Model moved to GPU")
else:
print("⚠️ Using CPU (GPU not available)")
print("βœ… Torch hub models working correctly")
except Exception as e:
print(f"❌ Torch hub model download failed: {e}")
traceback.print_exc()
def create_simple_test_notebook():
"""Create a simple test notebook for debugging."""
print("\nπŸ” CREATING SIMPLE TEST NOTEBOOK")
print("=" * 50)
simple_notebook = {
"cells": [
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"import torchaudio\n",
"import os\n",
"print('Python version:', sys.version)\n",
"print('PyTorch version:', torch.__version__)\n",
"print('CUDA available:', torch.cuda.is_available())\n",
"print('Current directory:', os.getcwd())"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Test simple audio loading\n",
"test_input = r'C:\\Users\\beyon\\Downloads\\LJ001-0005.wav'\n",
"if os.path.exists(test_input):\n",
" source, sr = torchaudio.load(test_input)\n",
" print(f'Audio loaded: shape={source.shape}, sr={sr}')\n",
" # Save a copy as output\n",
" output_path = r'C:\\Users\\beyon\\Downloads\\meity\\temp_outputs\\simple_test_output.wav'\n",
" os.makedirs(os.path.dirname(output_path), exist_ok=True)\n",
" torchaudio.save(output_path, source, sr)\n",
" print(f'Saved test output to: {output_path}')\n",
"else:\n",
" print(f'Test input file not found: {test_input}')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
import json
test_notebook_path = r"C:\Users\beyon\Downloads\meity\simple_test.ipynb"
try:
with open(test_notebook_path, 'w') as f:
json.dump(simple_notebook, f, indent=2)
print(f"βœ… Created simple test notebook: {test_notebook_path}")
# Try to execute it
result = subprocess.run([
'jupyter', 'nbconvert', '--to', 'notebook', '--execute', test_notebook_path
], capture_output=True, text=True, timeout=60)
if result.returncode == 0:
print("βœ… Simple notebook executed successfully")
else:
print("❌ Simple notebook execution failed")
print(f"Error: {result.stderr}")
except Exception as e:
print(f"❌ Error creating/executing simple notebook: {e}")
def main():
"""Run all tests."""
print("πŸš€ DYSARTHRIC VOICE CONVERSION - DEBUG TESTS")
print("=" * 60)
# Run all tests
test_dependencies()
test_file_paths()
test_audio_processor()
test_notebook_execution()
# Ask if user wants to test model downloads (takes time)
response = input("\nDo you want to test model downloads? (y/n): ").lower().strip()
if response == 'y':
test_torch_hub()
# Ask if user wants to create simple test notebook
response = input("\nDo you want to create and test a simple notebook? (y/n): ").lower().strip()
if response == 'y':
create_simple_test_notebook()
print("\n" + "=" * 60)
print("🏁 DEBUG TESTS COMPLETED")
print("\nIf you see any ❌ errors above, fix those first.")
print("Common fixes:")
print(" β€’ Install missing packages: pip install nbconvert nbformat jupyter")
print(" β€’ Check file paths and ensure all files exist")
print(" β€’ Verify internet connection for model downloads")
print(" β€’ Ensure CUDA is properly installed if using GPU")
if __name__ == "__main__":
main()