hammammahdy commited on
Commit
30fae3d
·
1 Parent(s): 2168f02

first commit

Browse files
Files changed (5) hide show
  1. app.py +9 -0
  2. header2.jpg +0 -0
  3. model_cv.h5 +3 -0
  4. prediction.py +81 -0
  5. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ # page = st.sidebar.selectbox('Pilih Halaman :', ('EDA', 'Prediction'))
6
+ # if page == 'EDA':
7
+ # eda.run()
8
+ # else:
9
+ prediction.run()
header2.jpg ADDED
model_cv.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c92b77282cea264739caaf64b4b3679ff343219e5013e129388673f239b99f25
3
+ size 600352
prediction.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ import matplotlib.pyplot as plt
6
+ from PIL import Image
7
+
8
+
9
+ def run():
10
+
11
+ # membuat title
12
+ st.title('Computer Vision Artificial Neural Network')
13
+
14
+ # membuat subheader
15
+ st.subheader('Prediction Between Daisy and Dandelion Flower')
16
+
17
+ # menambahkan gambar
18
+ image = Image.open('header2.jpg')
19
+ st.image(image)
20
+
21
+ # inference
22
+ model = tf.keras.models.load_model('model_cv.h5')
23
+
24
+ data_inf = st.file_uploader("Upload file image to predict", type=['jpg', 'png', 'jpeg'])
25
+
26
+ # submit button
27
+ submitted = st.button('Predict')
28
+
29
+ # logic ketika predict button ditekan
30
+ if submitted and data_inf:
31
+
32
+ img = Image.open(data_inf)
33
+ img = img.resize((150,150))
34
+
35
+
36
+ # img = tf.keras.utils.load_img(data_inf, target_size=(150, 150))
37
+ x = tf.keras.utils.img_to_array(img)/255
38
+
39
+ x = np.expand_dims(x, axis=0)
40
+
41
+ # menampilkan gambar upload
42
+ left_co, cent_co,last_co = st.columns(3)
43
+ with cent_co:
44
+ st.image(img, caption='Uploaded Image')
45
+
46
+ # prediksi
47
+ pred_inf = model.predict(x)[0,0]
48
+ threshold = 0.395
49
+
50
+ # menentukan kelas
51
+ if pred_inf >= threshold:
52
+ predicted_class = 0
53
+ else:
54
+ predicted_class = 1
55
+
56
+ clas = ['Daisy', 'Dandelion']
57
+ st.write('### Prediction :', clas[predicted_class])
58
+ st.write('#### Probability : {:.3f}'.format(pred_inf))
59
+
60
+
61
+ # images = np.vstack([x])
62
+ # output = model.predict(images, batch_size=32)
63
+ # probability = output[0, 0]
64
+ # threshold = 0.395 # threshold untuk klasifikasi biner
65
+
66
+ # if probability >= threshold:
67
+ # predicted_class = 0
68
+ # else:
69
+ # predicted_class = 1
70
+
71
+ # clas = ['daisy', 'dandelion']
72
+ # print('Prediction is a {} with probability {:.3f}'.format(clas[predicted_class], probability))
73
+
74
+ # # predict
75
+ # pred_inf = model.predict(data_inf)
76
+ # st.write('## Prediction :', str(int(pred_inf)))
77
+ # st.write('### Positive : 1, Negative : 2')
78
+
79
+ if __name__ == '__main__':
80
+ run()
81
+
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ streamlit==0.59.0
2
+ pandas
3
+ numpy
4
+ matplotlib
5
+ seaborn
6
+ plotly
7
+ Pillow
8
+ tensorflow
9
+ keras