Spaces:
Sleeping
Sleeping
Update src/prediction.py
Browse files- src/prediction.py +72 -75
src/prediction.py
CHANGED
@@ -1,76 +1,73 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import os
|
4 |
-
import sys
|
5 |
-
from io import BytesIO, StringIO
|
6 |
-
import tensorflow as tf
|
7 |
-
from PIL import Image
|
8 |
-
import numpy as np
|
9 |
-
|
10 |
-
# load files
|
11 |
-
|
12 |
-
model=tf.keras.models.load_model('./src/best_model_sore.keras')
|
13 |
-
|
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 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
#
|
38 |
-
|
39 |
-
# def
|
40 |
-
# self.fileTypes
|
41 |
-
|
42 |
-
#
|
43 |
-
#
|
44 |
-
#
|
45 |
-
#
|
46 |
-
#
|
47 |
-
#
|
48 |
-
#
|
49 |
-
|
50 |
-
#
|
51 |
-
#
|
52 |
-
|
53 |
-
|
54 |
-
#
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
# st.
|
62 |
-
|
63 |
-
#
|
64 |
-
#
|
65 |
-
|
66 |
-
#
|
67 |
-
|
68 |
-
#
|
69 |
-
#
|
70 |
-
|
71 |
-
|
72 |
-
#
|
73 |
-
# topi.close()
|
74 |
-
|
75 |
-
# run()
|
76 |
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
from io import BytesIO, StringIO
|
6 |
+
import tensorflow as tf
|
7 |
+
from PIL import Image
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
# load files
|
11 |
+
|
12 |
+
model=tf.keras.models.load_model('./src/best_model_sore.keras')
|
13 |
+
|
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 |
|