Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,10 @@ model = YOLO(YOLO_MODEL_PATH, task='detect').to("cpu") # Force CPU usage
|
|
9 |
def resize_and_pad(image, target_size=(640, 640)):
|
10 |
"""Resize image while keeping aspect ratio and padding to fit target size."""
|
11 |
original_size = image.size # (width, height)
|
12 |
-
|
13 |
-
|
|
|
|
|
14 |
# Create a new white background image
|
15 |
new_image = Image.new("RGB", target_size, (255, 255, 255))
|
16 |
|
@@ -54,17 +56,21 @@ def detect_lines(image):
|
|
54 |
|
55 |
return image_with_boxes
|
56 |
|
57 |
-
# Define Gradio interface
|
58 |
with gr.Blocks() as iface:
|
59 |
-
gr.Markdown("# Text Line Detection")
|
60 |
-
gr.Markdown("
|
61 |
|
62 |
-
with gr.
|
63 |
-
gr.
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# Launch Gradio interface
|
70 |
iface.launch()
|
|
|
9 |
def resize_and_pad(image, target_size=(640, 640)):
|
10 |
"""Resize image while keeping aspect ratio and padding to fit target size."""
|
11 |
original_size = image.size # (width, height)
|
12 |
+
|
13 |
+
# Use LANCZOS instead of ANTIALIAS (Fix for Pillow v10+)
|
14 |
+
image.thumbnail(target_size, Image.LANCZOS)
|
15 |
+
|
16 |
# Create a new white background image
|
17 |
new_image = Image.new("RGB", target_size, (255, 255, 255))
|
18 |
|
|
|
56 |
|
57 |
return image_with_boxes
|
58 |
|
59 |
+
# Define Gradio interface with two-column layout
|
60 |
with gr.Blocks() as iface:
|
61 |
+
gr.Markdown("# Text Line Detection with YOLOv8")
|
62 |
+
gr.Markdown("Upload an image and detect lines of text.")
|
63 |
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column(scale=1):
|
66 |
+
gr.Markdown("### Upload Image")
|
67 |
+
image_input = gr.Image(type="numpy", label="Upload an image")
|
68 |
+
|
69 |
+
with gr.Column(scale=1):
|
70 |
+
gr.Markdown("### Detected Text Lines")
|
71 |
+
image_output = gr.Image(type="pil", label="Detected lines")
|
72 |
+
|
73 |
+
image_input.upload(detect_lines, inputs=image_input, outputs=image_output)
|
74 |
|
75 |
# Launch Gradio interface
|
76 |
iface.launch()
|