Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,33 +2,22 @@ import os
|
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
try:
|
| 7 |
-
import pytesseract
|
| 8 |
-
except ImportError:
|
| 9 |
-
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pytesseract'])
|
| 10 |
-
import pytesseract
|
| 11 |
-
|
| 12 |
-
# Set Tesseract path
|
| 13 |
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
return text
|
| 30 |
-
except Exception as e:
|
| 31 |
-
return f"Error extracting text: {str(e)}"
|
| 32 |
import gradio as gr
|
| 33 |
import re
|
| 34 |
import numpy as np
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import sys
|
| 4 |
|
| 5 |
+
# Instead of hardcoding the path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
|
| 7 |
|
| 8 |
+
# Try this more flexible approach
|
| 9 |
+
try:
|
| 10 |
+
# First try the default path
|
| 11 |
+
if os.path.exists('/usr/bin/tesseract'):
|
| 12 |
+
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
|
| 13 |
+
# Try to find it on the PATH
|
| 14 |
+
else:
|
| 15 |
+
tesseract_path = subprocess.check_output(['which', 'tesseract']).decode().strip()
|
| 16 |
+
if tesseract_path:
|
| 17 |
+
pytesseract.pytesseract.tesseract_cmd = tesseract_path
|
| 18 |
+
except:
|
| 19 |
+
# If all else fails, try the default installation path
|
| 20 |
+
pytesseract.pytesseract.tesseract_cmd = 'tesseract'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
import gradio as gr
|
| 22 |
import re
|
| 23 |
import numpy as np
|