Spaces:
Sleeping
Sleeping
Update src/prediction.py
Browse files- 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 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
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()
|
|