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 Citra Kerang Menggunakan Algoritma CNN-Deep Learning

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

Harap Unggah Gambar Untuk Menemukan Kategorinya

''' st.set_option('deprecation.showfileUploaderEncoding', False) st.markdown(html_temp, unsafe_allow_html=True) opt = st.selectbox("Bagaimana Anda ingin mengunggah gambar untuk klasifikasi? (Harap Masukan Gambar Yang Jelas Agar Hasilnya Tidak Ambigu)\n", ('Silahkan Pilih', 'Unggah gambar melalui tautan', 'Unggah gambar dari perangkat')) if opt == 'Unggah gambar dari perangkat': 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 == 'Unggah gambar melalui tautan': try: img = st.text_input('Masukkan Tautan Gambar') 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 = 'Unggah Gambar') if st.button('Prediksi'): 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("Kemungkinan:",np.max(prediction[0], axis=-1)) st.info('Hai! Gambar yang diunggah telah diklasifikasikan sebagai " {} " '.format(labels[np.argmax(prediction[0], axis=-1)])) st.info('Kemungkinan '+ str(proba)) except Exception as e: st.info(e) pass