File size: 1,097 Bytes
3b99700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd0746e
 
3b99700
bd0746e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import streamlit as st
import pandas as pd
import os
import sys
from io import BytesIO, StringIO
import tensorflow as tf
from PIL import Image
import numpy as np

# load files

model=tf.keras.models.load_model('./src/best_model_sore.keras')

klas = ['baseball_cap', 'beanie_hat', 'bucket_hat', 'fedora_hat', 'flat_cap']

st.title('Jenis Topi')
def run():
    picup = st.file_uploader('Upload a picture', type=['jpg', 'jpeg', 'png'])
    
    if picup is not None:
        st.image(picup, caption='Uploaded Image', use_column_width=True)
    
        img = Image.open(picup).convert('RGB')
        img = img.resize((400,400))
        img_array = np.array(img)
        img_array = np.expand_dims(img_array, axis=0)
    
        prediction = model.predict(img_array)
        pred_index = np.argmax(prediction)
        pred_class = klas[pred_index]
        confidence = prediction[0][pred_index]*100
        st.write(f'Prediction: **{pred_class}** ({confidence:.2f}% confidence)')
        st.success(f'Prediction: **{pred_class}** ({confidence:.2f}% confidence)')

if __name__ == '__main__':
    run()