dev2607 commited on
Commit
07a8cb1
·
verified ·
1 Parent(s): 8ac4d44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -1,3 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import re
3
  import numpy as np
 
1
+ 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