Spaces:
Runtime error
Runtime error
import streamlit as st | |
import degirum as dg | |
from PIL import Image | |
import degirum_tools | |
# hw_location: Where you want to run inference. | |
# Use "@cloud" to use DeGirum cloud. | |
# Use "@local" to run on local machine. | |
# Use an IP address for AI server inference. | |
hw_location = "@cloud" | |
# model_zoo_url: URL/path for the model zoo. | |
# Use cloud_zoo_url for @cloud, @local, and AI server inference options. | |
# Use '' for an AI server serving models from a local folder. | |
# Use a path to a JSON file for a single model zoo in case of @local inference. | |
model_zoo_url = "https://cs.degirum.com/degirum/public" | |
# lp_det_model_name: Name of the model for license plate detection. | |
lp_det_model_name = "yolo_v5s_lp_det--512x512_quant_n2x_orca1_1" | |
# lp_ocr_model_name: Name of the model for license plate OCR. | |
lp_ocr_model_name = "yolo_v5s_lp_ocr--256x256_quant_n2x_orca1_1" | |
# Connect to AI inference engine | |
model_zoo = dg.connect(hw_location, model_zoo_url, token=st.secrets["DG_TOKEN"]) | |
# Load models | |
lp_det_model = model_zoo.load_model(lp_det_model_name, | |
image_backend='pil', | |
overlay_color=(255,0,0), | |
overlay_line_width=2, | |
overlay_font_scale=2 | |
) | |
lp_ocr_model= model_zoo.load_model(lp_ocr_model_name, image_backend='pil') | |
# Create a compound cropping model with 5% crop extent | |
crop_model = degirum_tools.CroppingAndClassifyingCompoundModel( | |
lp_det_model, lp_ocr_model, 5.0 | |
) | |
st.title('DeGirum Cloud Platform Demo of License Plate Detection and Recognition Models') | |
st.text('Upload an image. Then click on the submit button') | |
with st.form("model_form"): | |
uploaded_file=st.file_uploader('input image') | |
submitted = st.form_submit_button("Submit") | |
if submitted: | |
image = Image.open(uploaded_file) | |
image.thumbnail((512,512), Image.Resampling.LANCZOS) | |
inference_results=crop_model(image) | |
st.image(inference_results.image_overlay,caption='Image with Bounding Boxes') |