Download test_notebook_processing.py from Themozhi/meity: direct link, hf CLI and curl.
- Browser
- Download file 9.97 kB
-
https://huggingface.co/spaces/Themozhi/meity/resolve/main/test_notebook_processing.py
- Command line
-
hf download hf://spaces/Themozhi/meity/test_notebook_processing.py
-
curl -L -o test_notebook_processing.py https://huggingface.co/spaces/Themozhi/meity/resolve/main/test_notebook_processing.py
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() |