import streamlit as st import pandas as pd import numpy as np import joblib import cv2 from PIL import Image import sklearn import joblib try: model = joblib.load("knn_cls.pkl") st.success("Model Loaded Successfully") except Exception as e: st.error(e) st.title("Apple and Tomato Classification") image=st.file_uploader(label="upload only tomato and apple ",type='image/*') if image is not None: st.image(image) # file_bytes = np.asarray(bytearray(image.read()), dtype=np.uint8) # image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR) image=Image.open(image) image=np.array(image) image=cv2.resize(src=image,dsize=(100,100),interpolation=cv2.INTER_LINEAR) image=image.flatten() df=pd.DataFrame(image) df=df.T if st.button("Predict"): y_pred=model.predict(df) st.info(f"The predicted value is {y_pred[0]}")