import time import streamlit as st import numpy as np from PIL import Image import urllib.request from utils import * labels = gen_labels() html_temp = '''

Klasifikasi Kerang

''' st.markdown(html_temp, unsafe_allow_html=True) html_temp = '''

Please upload Image to find its Category

''' st.set_option('deprecation.showfileUploaderEncoding', False) st.markdown(html_temp, unsafe_allow_html=True) opt = st.selectbox("How do you want to upload the image for classification?\n", ('Please Select', 'Upload image via link', 'Upload image from device')) if opt == 'Upload image from device': file = st.file_uploader('Select', type = ['jpg', 'png', 'jpeg']) st.set_option('deprecation.showfileUploaderEncoding', False) if file is not None: image = Image.open(file) elif opt == 'Upload image via link': try: img = st.text_input('Enter the Image Address') image = Image.open(urllib.request.urlopen(img)) except: if st.button('Submit'): show = st.error("Please Enter a valid Image Address!") time.sleep(4) show.empty() try: if image is not None: st.image(image, width = 300, caption = 'Uploaded Image') if st.button('Predict'): img = preprocess(image) model = model_arc() model.load_weights("weights/model.h5") prediction = model.predict(img[np.newaxis, ...]) proba = np.max(prediction[0], axis=-1) print("Probability:",np.max(prediction[0], axis=-1)) st.info('Hey! The uploaded image has been classified as " {} " '.format(labels[np.argmax(prediction[0], axis=-1)])) st.info('Probability '+ str(proba)) except Exception as e: st.info(e) pass