Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,10 +22,10 @@ st.markdown(
|
|
| 22 |
This demo runs a simple **Automatic License Plate Recognition (ALPR)** pipeline
|
| 23 |
using models hosted on **DeGirum Cloud**.
|
| 24 |
|
| 25 |
-
**
|
| 26 |
-
1. Upload an image
|
| 27 |
2. Click **Run Inference**.
|
| 28 |
-
3.
|
| 29 |
"""
|
| 30 |
)
|
| 31 |
|
|
@@ -33,8 +33,9 @@ using models hosted on **DeGirum Cloud**.
|
|
| 33 |
# Configuration
|
| 34 |
# -----------------------------
|
| 35 |
hw_location = "@cloud"
|
| 36 |
-
model_zoo_url = "https://cs.degirum.com/degirum/degirum"
|
| 37 |
|
|
|
|
|
|
|
| 38 |
lp_det_model_name = "yolov8n_relu6_global_lp_det--640x640_quant_n2x_orca1_1"
|
| 39 |
lp_ocr_model_name = "yolov8s_relu6_lp_ocr_7ch--256x128_quant_n2x_orca1_1"
|
| 40 |
|
|
@@ -69,7 +70,7 @@ def load_compound_model():
|
|
| 69 |
crop_model = load_compound_model()
|
| 70 |
|
| 71 |
# -----------------------------
|
| 72 |
-
#
|
| 73 |
# -----------------------------
|
| 74 |
st.subheader("Upload an image")
|
| 75 |
|
|
@@ -78,28 +79,33 @@ uploaded_file = st.file_uploader(
|
|
| 78 |
type=["jpg", "jpeg", "png"],
|
| 79 |
)
|
| 80 |
|
|
|
|
| 81 |
if uploaded_file is not None:
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
preview = image.copy()
|
| 85 |
preview.thumbnail((800, 800), Image.Resampling.LANCZOS)
|
| 86 |
st.image(preview, caption="Original image", use_container_width=True)
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
if
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
model_input.thumbnail((640, 640), Image.Resampling.LANCZOS)
|
| 95 |
|
| 96 |
-
|
|
|
|
| 97 |
|
| 98 |
st.subheader("Detection result")
|
| 99 |
st.image(
|
| 100 |
-
|
| 101 |
caption="Image with license plate bounding boxes and labels",
|
| 102 |
use_container_width=True,
|
| 103 |
)
|
| 104 |
-
|
|
|
|
| 105 |
st.info("👈 Upload an image to get started.")
|
|
|
|
| 22 |
This demo runs a simple **Automatic License Plate Recognition (ALPR)** pipeline
|
| 23 |
using models hosted on **DeGirum Cloud**.
|
| 24 |
|
| 25 |
+
**How to use this demo:**
|
| 26 |
+
1. Upload an image containing a vehicle / license plate.
|
| 27 |
2. Click **Run Inference**.
|
| 28 |
+
3. The result image will show detected plates with OCR labels.
|
| 29 |
"""
|
| 30 |
)
|
| 31 |
|
|
|
|
| 33 |
# Configuration
|
| 34 |
# -----------------------------
|
| 35 |
hw_location = "@cloud"
|
|
|
|
| 36 |
|
| 37 |
+
# Model zoo and model names
|
| 38 |
+
model_zoo_url = "https://cs.degirum.com/degirum/degirum"
|
| 39 |
lp_det_model_name = "yolov8n_relu6_global_lp_det--640x640_quant_n2x_orca1_1"
|
| 40 |
lp_ocr_model_name = "yolov8s_relu6_lp_ocr_7ch--256x128_quant_n2x_orca1_1"
|
| 41 |
|
|
|
|
| 70 |
crop_model = load_compound_model()
|
| 71 |
|
| 72 |
# -----------------------------
|
| 73 |
+
# Upload + form
|
| 74 |
# -----------------------------
|
| 75 |
st.subheader("Upload an image")
|
| 76 |
|
|
|
|
| 79 |
type=["jpg", "jpeg", "png"],
|
| 80 |
)
|
| 81 |
|
| 82 |
+
# Show original image as soon as it’s uploaded (simple preview)
|
| 83 |
if uploaded_file is not None:
|
| 84 |
+
original_image = Image.open(uploaded_file).convert("RGB")
|
| 85 |
+
preview = original_image.copy()
|
|
|
|
| 86 |
preview.thumbnail((800, 800), Image.Resampling.LANCZOS)
|
| 87 |
st.image(preview, caption="Original image", use_container_width=True)
|
| 88 |
|
| 89 |
+
# Use a form for the button + inference (like your original code)
|
| 90 |
+
with st.form("lp_form"):
|
| 91 |
+
submitted = st.form_submit_button(
|
| 92 |
+
"Run Inference", disabled=uploaded_file is None
|
| 93 |
+
)
|
| 94 |
|
| 95 |
+
if submitted and uploaded_file is not None:
|
| 96 |
+
# Resize image for model input
|
| 97 |
+
image_for_model = original_image.copy()
|
| 98 |
+
image_for_model.thumbnail((640, 640), Image.Resampling.LANCZOS)
|
|
|
|
| 99 |
|
| 100 |
+
# Run compound model
|
| 101 |
+
inference_results = crop_model(image_for_model)
|
| 102 |
|
| 103 |
st.subheader("Detection result")
|
| 104 |
st.image(
|
| 105 |
+
inference_results.image_overlay,
|
| 106 |
caption="Image with license plate bounding boxes and labels",
|
| 107 |
use_container_width=True,
|
| 108 |
)
|
| 109 |
+
|
| 110 |
+
if uploaded_file is None:
|
| 111 |
st.info("👈 Upload an image to get started.")
|