shashichilappagari commited on
Commit
ee69519
·
verified ·
1 Parent(s): 45b69dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
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
- **Steps:**
26
- 1. Upload an image with a vehicle / license plate.
27
  2. Click **Run Inference**.
28
- 3. See the image with detected plates and OCR labels.
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
- # UI: upload + run
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
- # Show original image as soon as it's uploaded
83
- image = Image.open(uploaded_file).convert("RGB")
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
- run_button = st.button("Run Inference")
 
 
 
 
89
 
90
- if run_button:
91
- with st.spinner("Running license plate detection and recognition..."):
92
- # Use a copy resized for the model
93
- model_input = image.copy()
94
- model_input.thumbnail((640, 640), Image.Resampling.LANCZOS)
95
 
96
- results = crop_model(model_input)
 
97
 
98
  st.subheader("Detection result")
99
  st.image(
100
- results.image_overlay,
101
  caption="Image with license plate bounding boxes and labels",
102
  use_container_width=True,
103
  )
104
- else:
 
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.")