|
import streamlit as st |
|
from PIL import Image |
|
import random |
|
import sahi.utils.file |
|
import pandas as pd |
|
|
|
IMAGE_TO_URL = { |
|
'factory_pid.png' : 'https://d1afc1j4569hs1.cloudfront.net/factory-pid.png', |
|
'plant_pid.png' : 'https://d1afc1j4569hs1.cloudfront.net/plant-pid.png', |
|
'processing_pid.png' : 'https://d1afc1j4569hs1.cloudfront.net/processing-pid.png' |
|
} |
|
|
|
st.set_page_config( |
|
page_title="P&ID Object Detection", |
|
layout="wide", |
|
initial_sidebar_state="expanded" |
|
) |
|
|
|
st.title('P&ID Object Detection') |
|
st.subheader(' Identify valves and pumps with deep learning model ', divider='rainbow') |
|
st.caption('Developed by Deep Drawings Co.') |
|
|
|
col1, col2, col3 = st.columns([10, 10, 10]) |
|
with col2: |
|
with st.expander('How to use it'): |
|
st.markdown( |
|
''' |
|
1) Upload your P&ID or Select Test Diagrams π¬ |
|
2) Set Confidence Threshold π |
|
3) Press to Perform Inference π |
|
4) Visualize Model Predictions π |
|
''' |
|
) |
|
|
|
st.write('##') |
|
|
|
col1, col2, col3, col4, col5 = st.columns([8, 2, 8, 2, 8]) |
|
with col1: |
|
st.markdown('##### Input File') |
|
|
|
image_file = st.file_uploader("Upload your diagram", type=["pdf"]) |
|
|
|
def radio_func(option): |
|
option_to_id = { |
|
'factory_pid.png' : 'Factory P&ID', |
|
'plant_pid.png' : 'Plant P&ID', |
|
'processing_pid.png' : 'Processing P&ID', |
|
} |
|
return option_to_id[option] |
|
st.write('##') |
|
radio = st.radio( |
|
'Or select from example diagrams', |
|
options = ['factory_pid.png', 'plant_pid.png', 'processing_pid.png'], |
|
format_func = radio_func, |
|
|
|
) |
|
with col3: |
|
st.markdown('##### Preview') |
|
|
|
if image_file is not None: |
|
image = Image.open(image_file) |
|
else: |
|
image = sahi.utils.cv.read_image_as_pil(IMAGE_TO_URL[radio]) |
|
st.image(image, use_column_width = True) |