danupurnomo commited on
Commit
bd0746e
·
verified ·
1 Parent(s): 3b99700

Update src/prediction.py

Browse files
Files changed (1) hide show
  1. src/prediction.py +19 -56
src/prediction.py CHANGED
@@ -14,60 +14,23 @@ model=tf.keras.models.load_model('./src/best_model_sore.keras')
14
  klas = ['baseball_cap', 'beanie_hat', 'bucket_hat', 'fedora_hat', 'flat_cap']
15
 
16
  st.title('Jenis Topi')
17
-
18
- picup = st.file_uploader('Upload a picture', type=['jpg', 'jpeg', 'png'])
19
-
20
- if picup is not None:
21
- st.image(picup, caption='Uploaded Image', use_column_width=True)
22
-
23
- img = Image.open(picup).convert('RGB')
24
- img = img.resize((400,400))
25
- img_array = np.array(img)
26
- img_array = np.expand_dims(img_array, axis=0)
27
-
28
- prediction = model.predict(img_array)
29
- pred_index = np.argmax(prediction)
30
- pred_class = klas[pred_index]
31
- confidence = prediction[0][pred_index]*100
32
- st.write(f'Prediction: **{pred_class}** ({confidence:.2f}% confidence)')
33
-
34
- # class picupload(object):
35
-
36
- # def __init__(self):
37
- # self.fileTypes=['jpg']
38
-
39
- # def run(self):
40
- # topi = st.file_uploader('Upload picture', type=self.fileTypes)
41
- # show_file = st.empty()
42
- # if not topi:
43
- # show_file.info('Please upload a picture')
44
- # return
45
- # content = topi.getvalue()
46
- # if isinstance(topi, BytesIO):
47
- # show_file.image(topi)
48
- # topi.close()
49
-
50
- # if __name__ == '__main__':
51
- # helper = picupload()
52
- # helper.run()
53
-
54
- # def run():
55
 
56
- # with st.form(key='type-of-cap'):
57
-
58
- # st.write('##Topi')
59
-
60
- # topi = st.file_uploader('Upload file', type=['jpg'])
61
- # show_topi = st.empty()
62
-
63
- # if not topi:
64
- # show_topi.info('Please upload a picture : {}'.format(' '.join(['jpg'])))
65
- # return
66
- # content = topi.getvalue()
67
-
68
- # if isinstance(topi, BytesIO):
69
- # show_topi.image(topi)
70
- # topi.close()
71
-
72
- # run()
73
-
 
14
  klas = ['baseball_cap', 'beanie_hat', 'bucket_hat', 'fedora_hat', 'flat_cap']
15
 
16
  st.title('Jenis Topi')
17
+ def run():
18
+ picup = st.file_uploader('Upload a picture', type=['jpg', 'jpeg', 'png'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ if picup is not None:
21
+ st.image(picup, caption='Uploaded Image', use_column_width=True)
22
+
23
+ img = Image.open(picup).convert('RGB')
24
+ img = img.resize((400,400))
25
+ img_array = np.array(img)
26
+ img_array = np.expand_dims(img_array, axis=0)
27
+
28
+ prediction = model.predict(img_array)
29
+ pred_index = np.argmax(prediction)
30
+ pred_class = klas[pred_index]
31
+ confidence = prediction[0][pred_index]*100
32
+ st.write(f'Prediction: **{pred_class}** ({confidence:.2f}% confidence)')
33
+ st.success(f'Prediction: **{pred_class}** ({confidence:.2f}% confidence)')
34
+
35
+ if __name__ == '__main__':
36
+ run()