|
import streamlit as st |
|
import cv2 |
|
import torch |
|
from PIL import Image |
|
from doclayout_yolo import YOLOv10 |
|
import numpy as np |
|
|
|
|
|
model = YOLOv10("doclayout_yolo_docstructbench_imgsz1024.pt") |
|
|
|
|
|
device = 'cuda' if torch.cuda.is_available() else 'cpu' |
|
|
|
|
|
|
|
st.title("Document Layout Detection") |
|
st.subheader("Upload an image to detect and annotate document layout") |
|
|
|
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
|
|
|
|
|
|
image = Image.open(uploaded_file).convert("RGB") |
|
image_path = "temp_input.jpg" |
|
image.save(image_path) |
|
|
|
|
|
with st.spinner("Processing..."): |
|
det_res = model.predict( |
|
image_path, |
|
imgsz=1024, |
|
conf=0.2, |
|
device=device, |
|
) |
|
|
|
|
|
annotated_frame = det_res[0].plot(pil=True, line_width=5, font_size=20) |
|
|
|
|
|
annotated_image = np.array(annotated_frame) |
|
|
|
|
|
st.image(annotated_image, caption="Annotated Image", use_container_width=True) |
|
st.success("Detection completed!") |
|
|
|
|
|
st.markdown("**Application Created By Shubham Mhaske**") |
|
st.write("Do have a look on Papers π : - https://arxiv.org/pdf/2410.12628") |
|
st.write("Thanks to https://github.com/opendatalab") |
|
|