Norakneath commited on
Commit
64f1d49
·
verified ·
1 Parent(s): e6b1342

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
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
- image.thumbnail((target_size[0], target_size[1]), Image.ANTIALIAS) # Resize while keeping aspect ratio
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("## Upload an image to detect text lines")
61
 
62
- with gr.Tab("Upload Image"):
63
- gr.Markdown("Upload an image, and the YOLO model will detect lines of text.")
64
- image_input = gr.Image(type="numpy", label="Upload an image")
65
- image_output = gr.Image(type="pil", label="Detected lines")
66
-
67
- image_input.upload(detect_lines, inputs=image_input, outputs=image_output)
 
 
 
 
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()