Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,11 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
from flask import Flask, request, jsonify
|
| 5 |
from flask_cors import CORS
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import base64
|
| 8 |
|
| 9 |
-
# Initialize Flask
|
| 10 |
app = Flask(__name__)
|
| 11 |
CORS(app)
|
| 12 |
|
| 13 |
-
# Specify the Tesseract executable path (update this path if needed)
|
| 14 |
-
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
|
| 15 |
-
|
| 16 |
-
|
| 17 |
def decode_base64_image(image_data):
|
| 18 |
"""
|
| 19 |
Decode a Base64 image into OpenCV format.
|
|
@@ -32,8 +26,8 @@ def preprocess_image(image):
|
|
| 32 |
"""
|
| 33 |
Preprocess the image for better OCR results.
|
| 34 |
"""
|
| 35 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 36 |
-
_, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
|
| 37 |
return binary
|
| 38 |
|
| 39 |
|
|
@@ -71,14 +65,4 @@ def status():
|
|
| 71 |
|
| 72 |
|
| 73 |
if __name__ == '__main__':
|
| 74 |
-
try:
|
| 75 |
-
# Ensure Tesseract is installed
|
| 76 |
-
version = pytesseract.get_tesseract_version()
|
| 77 |
-
print(f"Tesseract OCR version: {version}")
|
| 78 |
-
except Exception as e:
|
| 79 |
-
print(f"Error: {e}")
|
| 80 |
-
print("Ensure Tesseract-OCR is installed and the path is correctly set.")
|
| 81 |
-
exit(1)
|
| 82 |
-
|
| 83 |
-
# Start the Flask server
|
| 84 |
app.run(debug=True, host='0.0.0.0', port=5000)
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from flask import Flask, request, jsonify
|
| 5 |
from flask_cors import CORS
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Initialize Flask app
|
| 8 |
app = Flask(__name__)
|
| 9 |
CORS(app)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def decode_base64_image(image_data):
|
| 12 |
"""
|
| 13 |
Decode a Base64 image into OpenCV format.
|
|
|
|
| 26 |
"""
|
| 27 |
Preprocess the image for better OCR results.
|
| 28 |
"""
|
| 29 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 30 |
+
_, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
|
| 31 |
return binary
|
| 32 |
|
| 33 |
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
app.run(debug=True, host='0.0.0.0', port=5000)
|