Spaces:
Sleeping
Sleeping
Create install_tesseract.py
Browse files- install_tesseract.py +39 -0
install_tesseract.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
def install_tesseract_windows():
|
| 6 |
+
# URL to the Tesseract installer
|
| 7 |
+
tesseract_installer_url = "https://github.com/UB-Mannheim/tesseract/wiki"
|
| 8 |
+
|
| 9 |
+
# PowerShell command to download the installer
|
| 10 |
+
powershell_command = f"""
|
| 11 |
+
$installerPath = "$env:TEMP\\tesseract-installer.exe"
|
| 12 |
+
Invoke-WebRequest -Uri "{tesseract_installer_url}" -OutFile $installerPath
|
| 13 |
+
Start-Process -FilePath $installerPath -ArgumentList "/S" -Wait
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
# Execute the PowerShell command
|
| 17 |
+
subprocess.run(["powershell", "-Command", powershell_command], check=True)
|
| 18 |
+
|
| 19 |
+
def install_python_dependencies():
|
| 20 |
+
# Install pytesseract and other dependencies
|
| 21 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "pytesseract", "opencv-python-headless", "Pillow", "streamlit"])
|
| 22 |
+
|
| 23 |
+
def verify_tesseract_installation():
|
| 24 |
+
try:
|
| 25 |
+
# Verify Tesseract installation
|
| 26 |
+
output = subprocess.check_output(["tesseract", "--version"], stderr=subprocess.STDOUT)
|
| 27 |
+
print(output.decode())
|
| 28 |
+
except subprocess.CalledProcessError as e:
|
| 29 |
+
print("Tesseract installation failed. Please try installing manually.")
|
| 30 |
+
print(e.output.decode())
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
try:
|
| 34 |
+
install_tesseract_windows()
|
| 35 |
+
install_python_dependencies()
|
| 36 |
+
verify_tesseract_installation()
|
| 37 |
+
print("Tesseract OCR and dependencies installed successfully.")
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"An error occurred: {e}")
|