license_plate / app.py
shashichilappagari's picture
Update app.py
2c9e18b
raw
history blame
2.66 kB
import streamlit as st
import degirum as dg
from PIL import Image
zoo=dg.connect(dg.CLOUD,zoo_url='https://cs.degirum.com/degirum/ultralytics_v6',token=st.secrets["DG_TOKEN"])
st.title('DeGirum Cloud Platform Demo')
with st.sidebar:
st.header('Specify Model Options Below')
runtime_agent_device=st.radio("Choose runtime agent device combo",("N2X-ORCA1","TFLite-EdgeTPU","OpenVINO-CPU"),index=0,horizontal=True)
activation_option=st.radio( 'Select activation function', ['relu6', 'silu'],horizontal=True)
dataset_option=st.radio( 'Select a dataset option', ['coco', 'face','lp','car','hand'],horizontal=True)
show_labels=st.toggle('Show labels in output',value=True)
show_probabilities=st.toggle('Show probabilities in output',value=False)
runtime_agent,device=runtime_agent_device.split('-')[0],runtime_agent_device.split('-')[1]
model_options=zoo.list_models(device=device,runtime=runtime_agent)
st.header('Choose and Run a Model')
st.text('Select a model and upload an image. Then click on the submit button')
with st.form("model_form"):
filtered_model_list=[]
for model in model_options:
if activation_option in model and dataset_option in model:
filtered_model_list.append(model)
st.write('Number of models found = ', len(filtered_model_list))
model_name=st.selectbox("Choose a Model from the list", filtered_model_list)
uploaded_file=st.file_uploader('input image')
submitted = st.form_submit_button("Submit")
if submitted:
model=zoo.load_model(model_name,
overlay_show_labels=show_labels,
overlay_show_probabilities=show_probabilities,
overlay_font_scale=3,
overlay_line_width=6,
image_backend='pil'
)
if model.output_postprocess_type=='PoseDetection':
model.overlay_show_labels=False
st.write("Model loaded successfully")
image = Image.open(uploaded_file)
predictions=model(image)
if model.output_postprocess_type=='Classification' or model.output_postprocess_type=='DetectionYoloPlates':
st.image(predictions.image,caption='Original Image')
st.write(predictions.results)
else:
st.image(predictions.image_overlay,caption='Image with Bounding Boxes/Keypoints')
model.measure_time=True
predictions=model(image)
stats=model.time_stats()
st.write('Expected Frames per second for the model= ', 1000.0/stats["CoreInferenceDuration_ms"].avg)