Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| import tensorflow as tf | |
| import matplotlib.pyplot as plt | |
| from PIL import Image | |
| def run(): | |
| # membuat title | |
| st.title('Computer Vision Artificial Neural Network') | |
| # membuat subheader | |
| st.subheader('Prediction Between Daisy and Dandelion Flower') | |
| # menambahkan gambar | |
| image = Image.open('header2.jpg') | |
| st.image(image) | |
| # inference | |
| model = tf.keras.models.load_model('model_cv.h5') | |
| data_inf = st.file_uploader("Upload file image to predict", type=['jpg', 'png', 'jpeg']) | |
| # submit button | |
| submitted = st.button('Predict') | |
| # logic ketika predict button ditekan | |
| if submitted and data_inf: | |
| img = Image.open(data_inf) | |
| img = img.resize((150,150)) | |
| # img = tf.keras.utils.load_img(data_inf, target_size=(150, 150)) | |
| x = tf.keras.utils.img_to_array(img)/255 | |
| x = np.expand_dims(x, axis=0) | |
| # menampilkan gambar upload | |
| left_co, cent_co,last_co = st.columns(3) | |
| with cent_co: | |
| st.image(img, caption='Uploaded Image') | |
| # prediksi | |
| pred_inf = model.predict(x)[0,0] | |
| threshold = 0.395 | |
| # menentukan kelas | |
| if pred_inf >= threshold: | |
| predicted_class = 0 | |
| else: | |
| predicted_class = 1 | |
| clas = ['Daisy', 'Dandelion'] | |
| st.write('### Prediction :', clas[predicted_class]) | |
| st.write('#### Probability : {:.3f}'.format(pred_inf)) | |
| # images = np.vstack([x]) | |
| # output = model.predict(images, batch_size=32) | |
| # probability = output[0, 0] | |
| # threshold = 0.395 # threshold untuk klasifikasi biner | |
| # if probability >= threshold: | |
| # predicted_class = 0 | |
| # else: | |
| # predicted_class = 1 | |
| # clas = ['daisy', 'dandelion'] | |
| # print('Prediction is a {} with probability {:.3f}'.format(clas[predicted_class], probability)) | |
| # # predict | |
| # pred_inf = model.predict(data_inf) | |
| # st.write('## Prediction :', str(int(pred_inf))) | |
| # st.write('### Positive : 1, Negative : 2') | |
| if __name__ == '__main__': | |
| run() | |