Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import LayoutLMv3Processor, LayoutLMv3ForTokenClassification
|
4 |
-
|
5 |
-
# Explicitly set the Tesseract path
|
6 |
-
# For Hugging Face Spaces, set this to the default Linux path
|
7 |
import pytesseract
|
|
|
8 |
|
9 |
-
#
|
10 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# For local development on Windows
|
15 |
# Uncomment the line below if running locally on Windows
|
16 |
# pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
|
17 |
|
18 |
-
|
19 |
-
|
20 |
# Load the model and processor
|
21 |
processor = LayoutLMv3Processor.from_pretrained("quadranttechnologies/Table_OCR")
|
22 |
model = LayoutLMv3ForTokenClassification.from_pretrained("quadranttechnologies/Table_OCR")
|
@@ -57,7 +60,9 @@ def process_image(image):
|
|
57 |
return structured_output
|
58 |
|
59 |
except Exception as e:
|
60 |
-
|
|
|
|
|
61 |
|
62 |
# Define the Gradio interface
|
63 |
interface = gr.Interface(
|
@@ -70,8 +75,11 @@ interface = gr.Interface(
|
|
70 |
|
71 |
# Launch the app
|
72 |
if __name__ == "__main__":
|
|
|
|
|
73 |
interface.launch(share=True)
|
74 |
|
75 |
|
76 |
|
77 |
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from transformers import LayoutLMv3Processor, LayoutLMv3ForTokenClassification
|
|
|
|
|
|
|
4 |
import pytesseract
|
5 |
+
import os
|
6 |
|
7 |
+
# Explicitly set the Tesseract path for Hugging Face Spaces
|
8 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
9 |
|
10 |
+
# Debugging: Print Tesseract version and PATH details
|
11 |
+
try:
|
12 |
+
tesseract_version = pytesseract.get_tesseract_version()
|
13 |
+
print("Tesseract Version:", tesseract_version)
|
14 |
+
print("Tesseract Path:", pytesseract.pytesseract.tesseract_cmd)
|
15 |
+
print("Environment PATH:", os.environ["PATH"])
|
16 |
+
except Exception as e:
|
17 |
+
print("Tesseract Debugging Error:", e)
|
18 |
|
19 |
# For local development on Windows
|
20 |
# Uncomment the line below if running locally on Windows
|
21 |
# pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
|
22 |
|
|
|
|
|
23 |
# Load the model and processor
|
24 |
processor = LayoutLMv3Processor.from_pretrained("quadranttechnologies/Table_OCR")
|
25 |
model = LayoutLMv3ForTokenClassification.from_pretrained("quadranttechnologies/Table_OCR")
|
|
|
60 |
return structured_output
|
61 |
|
62 |
except Exception as e:
|
63 |
+
# Debugging: Log any errors encountered during processing
|
64 |
+
print("Error during processing:", str(e))
|
65 |
+
return {"error": str(e)}
|
66 |
|
67 |
# Define the Gradio interface
|
68 |
interface = gr.Interface(
|
|
|
75 |
|
76 |
# Launch the app
|
77 |
if __name__ == "__main__":
|
78 |
+
# Debugging: Check if the app is starting correctly
|
79 |
+
print("Starting Table OCR App...")
|
80 |
interface.launch(share=True)
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
+
|