Spaces:
Runtime error
Runtime error
Revert "reaplce tesseract with easyocr"
Browse filesThis reverts commit 32ccca849381515ffc44bd2dd197292ff0bea173.
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import hf_hub_download
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
-
import
|
| 6 |
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
| 7 |
|
| 8 |
# Load the processor and model for table structure recognition
|
|
@@ -13,9 +13,6 @@ model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer
|
|
| 13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
model.to(device)
|
| 15 |
|
| 16 |
-
# Initialize EasyOCR Reader
|
| 17 |
-
reader = easyocr.Reader(['en']) # You can specify the language (e.g., 'en' for English)
|
| 18 |
-
|
| 19 |
# Define the inference and OCR function
|
| 20 |
def predict(image):
|
| 21 |
# Preprocess the input image
|
|
@@ -56,8 +53,8 @@ def predict(image):
|
|
| 56 |
# Crop the image to the bounding box area
|
| 57 |
cropped_image = image.crop((left, top, right, bottom))
|
| 58 |
|
| 59 |
-
# Perform OCR
|
| 60 |
-
ocr_text =
|
| 61 |
|
| 62 |
# Append OCR result for this box
|
| 63 |
ocr_results.append({
|
|
@@ -77,3 +74,4 @@ interface = gr.Interface(
|
|
| 77 |
|
| 78 |
# Launch the Gradio app
|
| 79 |
interface.launch()
|
|
|
|
|
|
| 2 |
from huggingface_hub import hf_hub_download
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
+
import pytesseract
|
| 6 |
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
| 7 |
|
| 8 |
# Load the processor and model for table structure recognition
|
|
|
|
| 13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
model.to(device)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
# Define the inference and OCR function
|
| 17 |
def predict(image):
|
| 18 |
# Preprocess the input image
|
|
|
|
| 53 |
# Crop the image to the bounding box area
|
| 54 |
cropped_image = image.crop((left, top, right, bottom))
|
| 55 |
|
| 56 |
+
# Perform OCR on the cropped image
|
| 57 |
+
ocr_text = pytesseract.image_to_string(cropped_image)
|
| 58 |
|
| 59 |
# Append OCR result for this box
|
| 60 |
ocr_results.append({
|
|
|
|
| 74 |
|
| 75 |
# Launch the Gradio app
|
| 76 |
interface.launch()
|
| 77 |
+
#recheck gradio bugging
|