bacancydataprophets/Metal_Defect_Detection
0
1import streamlit as st2from PIL import Image3import matplotlib.pyplot as plt4import matplotlib.patches as patches5from detect import Detection6from classify import Classification7from compare import Compare8 9# Streamlit app10def main():11 st.title("Metal Defect Detection and Classification App")12 det_res = Detection()13 cls_res = Classification()14 comp = Compare()15 uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])16 17 if uploaded_file is not None:18 # Display uploaded image19 image = Image.open(uploaded_file)20 st.image(image, caption='Uploaded Image', use_column_width=True)21 22 df = det_res.detect_defect(image)23 df1 = cls_res.classify_defect(image)24 25 # Perform comparison between scores of detection and classification26 detection_results = comp.comparison(df, df1)27 28 # Display results29 fig, ax = plt.subplots(1)30 ax.imshow(image)31 32 for index, row in detection_results.iterrows():33 x1, y1, x2, y2 = row['x1'], row['y1'], row['x2'], row['y2']34 width, height = x2 - x1, y2 - y135 rect = patches.Rectangle((x1, y1), width, height, linewidth=1, edgecolor='r', facecolor='none')36 ax.add_patch(rect)37 ax.text(x1, y1 - 5, f"{row['fnl_cls']}: {row['fnl_pred']:.2f}", color='r')38 39 ax.axis('off')40 st.pyplot(fig)41 42# Run the app43if __name__ == "__main__":44 main()