Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from PIL import Image, ImageDraw, ImageFont
|
|
| 4 |
import json
|
| 5 |
from paddleocr import PaddleOCR
|
| 6 |
import gradio as gr
|
| 7 |
-
import os
|
| 8 |
|
| 9 |
# Initialize PaddleOCR
|
| 10 |
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
|
@@ -27,8 +26,11 @@ def draw_boxes_on_image(image, data):
|
|
| 27 |
for item in data:
|
| 28 |
bounding_box, (text, confidence) = item
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Draw the bounding box
|
| 34 |
draw.line([tuple(box[0]), tuple(box[1])], fill="green", width=2)
|
|
@@ -50,6 +52,11 @@ def save_results_to_json(ocr_results):
|
|
| 50 |
for word_info in line:
|
| 51 |
bounding_box = word_info[0]
|
| 52 |
text, confidence = word_info[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
results.append({
|
| 54 |
"bounding_box": [list(map(float, coord)) for coord in bounding_box],
|
| 55 |
"text": text,
|
|
|
|
| 4 |
import json
|
| 5 |
from paddleocr import PaddleOCR
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
| 8 |
# Initialize PaddleOCR
|
| 9 |
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
|
|
|
| 26 |
for item in data:
|
| 27 |
bounding_box, (text, confidence) = item
|
| 28 |
|
| 29 |
+
# Ensure bounding_box is a list of lists
|
| 30 |
+
if isinstance(bounding_box[0], list):
|
| 31 |
+
box = np.array(bounding_box).astype(int)
|
| 32 |
+
else:
|
| 33 |
+
box = np.array([bounding_box]).astype(int)
|
| 34 |
|
| 35 |
# Draw the bounding box
|
| 36 |
draw.line([tuple(box[0]), tuple(box[1])], fill="green", width=2)
|
|
|
|
| 52 |
for word_info in line:
|
| 53 |
bounding_box = word_info[0]
|
| 54 |
text, confidence = word_info[1]
|
| 55 |
+
|
| 56 |
+
# Ensure bounding_box is a list of lists
|
| 57 |
+
if not isinstance(bounding_box[0], list):
|
| 58 |
+
bounding_box = [bounding_box]
|
| 59 |
+
|
| 60 |
results.append({
|
| 61 |
"bounding_box": [list(map(float, coord)) for coord in bounding_box],
|
| 62 |
"text": text,
|