Spaces:
Sleeping
Sleeping
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}") | |