File size: 9,967 Bytes
426f1f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/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()