File size: 1,957 Bytes
f69fe68
 
 
 
c9e9625
bde553b
 
 
f69fe68
c9e9625
 
 
bde553b
f69fe68
c9e9625
 
 
f69fe68
 
c9e9625
 
 
 
 
 
f69fe68
 
 
 
 
71b762e
f69fe68
 
 
 
 
 
 
 
 
c9e9625
f69fe68
 
c9e9625
f69fe68
 
 
 
 
 
 
 
71b762e
0579ad5
 
f69fe68
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import numpy as np
from PIL import Image
import tensorflow as tf
from tensorflow.keras.models import load_model
import tensorflow_hub as hub



# Load model sekali saat aplikasi di-start
@st.cache_resource
def load_skin_model():
    return load_model('model_aug.keras', custom_objects={'KerasLayer': hub.KerasLayer})

model = load_skin_model()

# Kelas target
CLASS_NAMES = ['oily', 'dry', 'normal']

def preprocess_image(image):
    """Preprocess image to match model input."""
    img_resized = tf.image.resize(image, [220, 220])  # Resize gambar
    img_normalized = img_resized / 255.0  # Normalisasi
    return tf.expand_dims(img_normalized, axis=0)  # Tambah batch dimension

def run():
    st.title('Skin Type Classification')
    st.write('---')
    st.write('Upload an image of skin, and this app will predict the skin type.')

    link_gambar = 'https://belomed.com/wp-content/uploads/2024/01/Know-your-skin-type.jpg'
    st.image(link_gambar, caption='Know your skin type!', use_container_width=True)

    uploaded_file = st.file_uploader('Upload an image:', type=['jpg', 'png', 'jpeg'])

    if uploaded_file is not None:
        image = Image.open(uploaded_file)
        st.image(image, caption='Uploaded Image', use_column_width=True)

        img_array = np.array(image)
        img_tensor = preprocess_image(img_array)

        # Prediksi menggunakan model
        prediction = model.predict(img_tensor)
        predicted_class = CLASS_NAMES[np.argmax(prediction)]
        confidence = np.max(prediction) * 100

        st.write(f"### Predicted Skin Type: {predicted_class}")
        st.write(f"### Confidence: {confidence:.2f}%")
    else:
        st.write('Please upload an image to get a prediction.')

    link_gambar = 'https://www.wendygriffith.co.uk/wp-content/uploads/sites/14118/2024/07/Healthy-Skin-1-1-1024x1024.png'
    st.image(link_gambar, use_container_width=True)

if __name__ == '__main__':
    run()