Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -45,6 +45,13 @@ def detect_and_crop_lines(image):
|
|
45 |
draw.text((x1, y1 - 10), f"Line {idx}", fill="blue")
|
46 |
|
47 |
cropped_line = image.crop((x1, y1, x2, y2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
cropped_lines.append(cropped_line)
|
49 |
|
50 |
return original_image, cropped_lines
|
@@ -62,22 +69,18 @@ with gr.Blocks() as iface:
|
|
62 |
gr.Markdown("### Annotated Image with Detected Lines")
|
63 |
output_annotated = gr.Image(type="pil", label="Detected Text Lines")
|
64 |
|
65 |
-
gr.Markdown("### Cropped Text Lines (
|
66 |
-
|
67 |
-
|
68 |
-
for i in range(20):
|
69 |
-
with gr.Row():
|
70 |
-
cropped_output_rows.append(gr.Image(type="pil", label=f"Line {i+1}"))
|
71 |
|
72 |
def process_and_display(image):
|
73 |
annotated_img, cropped_imgs = detect_and_crop_lines(image)
|
74 |
-
|
75 |
-
return [annotated_img] + cropped_imgs[:20]
|
76 |
|
77 |
image_input.upload(
|
78 |
process_and_display,
|
79 |
inputs=image_input,
|
80 |
-
outputs=[output_annotated]
|
81 |
)
|
82 |
|
83 |
iface.launch()
|
|
|
45 |
draw.text((x1, y1 - 10), f"Line {idx}", fill="blue")
|
46 |
|
47 |
cropped_line = image.crop((x1, y1, x2, y2))
|
48 |
+
|
49 |
+
# Resize the cropped line to a smaller fixed width while maintaining aspect ratio
|
50 |
+
fixed_width = 200
|
51 |
+
aspect_ratio = cropped_line.height / cropped_line.width
|
52 |
+
new_height = int(fixed_width * aspect_ratio)
|
53 |
+
cropped_line = cropped_line.resize((fixed_width, new_height), Image.LANCZOS)
|
54 |
+
|
55 |
cropped_lines.append(cropped_line)
|
56 |
|
57 |
return original_image, cropped_lines
|
|
|
69 |
gr.Markdown("### Annotated Image with Detected Lines")
|
70 |
output_annotated = gr.Image(type="pil", label="Detected Text Lines")
|
71 |
|
72 |
+
gr.Markdown("### Cropped Text Lines (Small Fixed-Size Previews)")
|
73 |
+
|
74 |
+
cropped_output = gr.Gallery(label="Detected Text Lines", columns=1, preview=True)
|
|
|
|
|
|
|
75 |
|
76 |
def process_and_display(image):
|
77 |
annotated_img, cropped_imgs = detect_and_crop_lines(image)
|
78 |
+
return annotated_img, cropped_imgs
|
|
|
79 |
|
80 |
image_input.upload(
|
81 |
process_and_display,
|
82 |
inputs=image_input,
|
83 |
+
outputs=[output_annotated, cropped_output]
|
84 |
)
|
85 |
|
86 |
iface.launch()
|