-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
44 lines (35 loc) · 1.47 KB
/
interface.py
File metadata and controls
44 lines (35 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
from PIL import Image
try:
from object_detection.detection import detect_objects
except Exception:
from detection import detect_objects
st.set_page_config(page_title="Object Detection", layout="centered")
st.title("Object Detection (DETR)")
threshold = st.slider("Confidence threshold", min_value=0.0, max_value=1.0, value=0.9, step=0.05)
device_choice = st.selectbox("Device", options=["Auto", "CPU", "CUDA"], index=0)
uploaded = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg", "webp"])
if uploaded is not None:
image = Image.open(uploaded).convert("RGB")
st.image(image, caption="Input image", use_container_width=True)
if st.button("Run detection", type="primary"):
device = None
if device_choice == "CPU":
device = "cpu"
elif device_choice == "CUDA":
device = "cuda"
try:
with st.spinner("Running model..."):
rows = detect_objects(image, threshold=threshold, device=device)
except Exception as exc:
st.error(str(exc))
st.stop()
if not rows:
st.info("No objects detected at this threshold.")
else:
st.subheader("Detections")
try:
import pandas as pd # type: ignore
st.dataframe(pd.DataFrame(rows), use_container_width=True, hide_index=True)
except Exception:
st.dataframe(rows, use_container_width=True)