Spaces:
Sleeping
Sleeping
File size: 1,485 Bytes
41a8187 |
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 |
import os
import subprocess
import sys
def install_tesseract_windows():
# URL to the Tesseract installer
tesseract_installer_url = "https://github.com/UB-Mannheim/tesseract/wiki"
# PowerShell command to download the installer
powershell_command = f"""
$installerPath = "$env:TEMP\\tesseract-installer.exe"
Invoke-WebRequest -Uri "{tesseract_installer_url}" -OutFile $installerPath
Start-Process -FilePath $installerPath -ArgumentList "/S" -Wait
"""
# Execute the PowerShell command
subprocess.run(["powershell", "-Command", powershell_command], check=True)
def install_python_dependencies():
# Install pytesseract and other dependencies
subprocess.check_call([sys.executable, "-m", "pip", "install", "pytesseract", "opencv-python-headless", "Pillow", "streamlit"])
def verify_tesseract_installation():
try:
# Verify Tesseract installation
output = subprocess.check_output(["tesseract", "--version"], stderr=subprocess.STDOUT)
print(output.decode())
except subprocess.CalledProcessError as e:
print("Tesseract installation failed. Please try installing manually.")
print(e.output.decode())
if __name__ == "__main__":
try:
install_tesseract_windows()
install_python_dependencies()
verify_tesseract_installation()
print("Tesseract OCR and dependencies installed successfully.")
except Exception as e:
print(f"An error occurred: {e}")
|