|
|
|
""" |
|
Fix NumPy compatibility issue for Video Transcription Service |
|
""" |
|
|
|
import subprocess |
|
import sys |
|
import os |
|
|
|
def run_command(command, description): |
|
"""Run a command and handle errors""" |
|
print(f"π§ {description}...") |
|
try: |
|
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True) |
|
print(f"β
{description} completed") |
|
if result.stdout.strip(): |
|
print(f" Output: {result.stdout.strip()}") |
|
return True |
|
except subprocess.CalledProcessError as e: |
|
print(f"β {description} failed:") |
|
print(f" Command: {command}") |
|
print(f" Error: {e.stderr}") |
|
return False |
|
|
|
def check_numpy_version(): |
|
"""Check current NumPy version""" |
|
try: |
|
import numpy as np |
|
version = np.__version__ |
|
print(f"π Current NumPy version: {version}") |
|
|
|
|
|
major_version = int(version.split('.')[0]) |
|
if major_version >= 2: |
|
print("β οΈ NumPy 2.x detected - this causes compatibility issues with PyTorch/Whisper") |
|
return False |
|
else: |
|
print("β
NumPy version is compatible") |
|
return True |
|
except ImportError: |
|
print("β NumPy not installed") |
|
return False |
|
|
|
def fix_numpy_compatibility(): |
|
"""Fix NumPy compatibility by downgrading to 1.x""" |
|
commands = [ |
|
("pip uninstall -y numpy", "Uninstalling current NumPy"), |
|
("pip install 'numpy<2.0.0'", "Installing compatible NumPy version"), |
|
("pip install --force-reinstall torch==2.1.0 torchaudio==2.1.0", "Reinstalling PyTorch with compatible NumPy"), |
|
("pip install --force-reinstall openai-whisper==20231117", "Reinstalling Whisper with compatible NumPy") |
|
] |
|
|
|
for command, description in commands: |
|
if not run_command(command, description): |
|
return False |
|
return True |
|
|
|
def verify_installation(): |
|
"""Verify that everything works after the fix""" |
|
print("\nπ§ͺ Testing installation...") |
|
|
|
try: |
|
|
|
import numpy as np |
|
print(f"β
NumPy {np.__version__} imported successfully") |
|
|
|
|
|
import torch |
|
print(f"β
PyTorch {torch.__version__} imported successfully") |
|
|
|
|
|
import whisper |
|
print("β
Whisper imported successfully") |
|
|
|
|
|
print("π Testing Whisper model loading...") |
|
try: |
|
|
|
model = whisper.load_model("tiny") |
|
print("β
Whisper model loaded successfully") |
|
return True |
|
except Exception as e: |
|
print(f"β οΈ Whisper model loading failed: {e}") |
|
print(" This might be due to network issues - try running the service anyway") |
|
return True |
|
|
|
except Exception as e: |
|
print(f"β Installation verification failed: {e}") |
|
return False |
|
|
|
def main(): |
|
print("π§ NumPy Compatibility Fix for Video Transcription Service") |
|
print("=" * 60) |
|
|
|
|
|
if check_numpy_version(): |
|
print("\nβ
NumPy version is already compatible!") |
|
print("If you're still getting errors, try restarting your service.") |
|
return |
|
|
|
print("\nπ§ Fixing NumPy compatibility...") |
|
|
|
|
|
if not fix_numpy_compatibility(): |
|
print("\nβ Failed to fix NumPy compatibility") |
|
print("\nπ‘ Manual fix:") |
|
print("1. pip uninstall numpy") |
|
print("2. pip install 'numpy<2.0.0'") |
|
print("3. pip install --force-reinstall torch torchaudio openai-whisper") |
|
sys.exit(1) |
|
|
|
|
|
if not verify_installation(): |
|
print("\nβ οΈ Installation verification had issues") |
|
print("Try running the service - it might still work") |
|
|
|
print("\nπ NumPy compatibility fix completed!") |
|
print("=" * 40) |
|
print("\nπ Next steps:") |
|
print("1. Restart your transcription service:") |
|
print(" python main.py") |
|
print(" OR") |
|
print(" python start.py") |
|
print("2. Test with a video file") |
|
print("\nπ‘ If you still get errors, try:") |
|
print("- Restart your terminal/command prompt") |
|
print("- Deactivate and reactivate your virtual environment") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|