|
import streamlit as st
|
|
import cv2
|
|
import torch
|
|
from PIL import Image
|
|
from doclayout_yolo import YOLOv10
|
|
import numpy as np
|
|
|
|
|
|
model = YOLOv10("model/doclayout_yolo_docstructbench_imgsz1024.pt")
|
|
|
|
|
|
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
st.write(f"Using device: {device}")
|
|
|
|
|
|
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:
|
|
|
|
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
|
|
|
|
|
|
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!")
|
|
|