dev2607 commited on
Commit
8e24c55
·
verified ·
1 Parent(s): 35dd3fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -2,33 +2,22 @@ import os
2
  import subprocess
3
  import sys
4
 
5
- # Attempt to install pytesseract if not found
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
- def extract_text_from_image(image):
16
- try:
17
- if image is None:
18
- return "No image captured. Please try again."
19
-
20
- # Verify Tesseract executable
21
- if not os.path.exists('/usr/bin/tesseract'):
22
- return "Tesseract OCR is not installed. Please install tesseract-ocr."
23
-
24
- text = pytesseract.image_to_string(image)
25
-
26
- if not text.strip():
27
- return "No text could be extracted. Ensure image is clear and readable."
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