Spaces:
Runtime error
Runtime error
Update prediction.py
Browse files- prediction.py +53 -53
prediction.py
CHANGED
|
@@ -1,53 +1,53 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
-
import cv2
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import tensorflow as tf
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
-
# Load model yang telah dilatih (ganti 'model.h5' dengan file model kamu)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# Kelas target (ubah sesuai dengan model kamu)
|
| 12 |
-
CLASS_NAMES = ['oily', 'dry', 'normal']
|
| 13 |
-
|
| 14 |
-
def run():
|
| 15 |
-
# Set judul aplikasi
|
| 16 |
-
st.title('Skin Type Classification')
|
| 17 |
-
st.write('---')
|
| 18 |
-
|
| 19 |
-
# Tambahkan deskripsi
|
| 20 |
-
st.write('Upload an image of skin, and this app will predict the skin type.')
|
| 21 |
-
|
| 22 |
-
# Gambar ilustrasi (opsional)
|
| 23 |
-
link_gambar = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQntnqn33t_1jWqaFszEgEdMCQjGNNtWLxv8A&s' # Ganti dengan URL gambar
|
| 24 |
-
st.image(link_gambar, caption='Know your skin type!', use_container_width=True)
|
| 25 |
-
|
| 26 |
-
# Form untuk upload gambar
|
| 27 |
-
uploaded_file = st.file_uploader('Upload an image:', type=['jpg', 'png', 'jpeg'])
|
| 28 |
-
|
| 29 |
-
if uploaded_file is not None:
|
| 30 |
-
# Tampilkan gambar yang di-upload
|
| 31 |
-
image = Image.open(uploaded_file)
|
| 32 |
-
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 33 |
-
|
| 34 |
-
# Convert gambar ke format yang diterima model
|
| 35 |
-
img_array = np.array(image)
|
| 36 |
-
img_resized = cv2.resize(img_array, (220, 220)) # Ubah ukuran ke input model
|
| 37 |
-
img_normalized = img_resized / 255.0 # Normalisasi
|
| 38 |
-
img_expanded = np.expand_dims(img_normalized, axis=0) # Tambahkan batch dimension
|
| 39 |
-
|
| 40 |
-
# Prediksi menggunakan model
|
| 41 |
-
prediction = model.predict(img_expanded)
|
| 42 |
-
predicted_class = CLASS_NAMES[np.argmax(prediction)]
|
| 43 |
-
confidence = np.max(prediction) * 100
|
| 44 |
-
|
| 45 |
-
# Tampilkan hasil prediksi
|
| 46 |
-
st.write(f"### Predicted Skin Type: {predicted_class}")
|
| 47 |
-
st.write(f"### Confidence: {confidence:.2f}%")
|
| 48 |
-
|
| 49 |
-
else:
|
| 50 |
-
st.write('Please upload an image to get a prediction.')
|
| 51 |
-
|
| 52 |
-
if __name__ == '__main__':
|
| 53 |
-
run()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Load model yang telah dilatih (ganti 'model.h5' dengan file model kamu)
|
| 9 |
+
model = load_model('model_aug.keras', custom_objects={'KerasLayer': KerasLayer})
|
| 10 |
+
|
| 11 |
+
# Kelas target (ubah sesuai dengan model kamu)
|
| 12 |
+
CLASS_NAMES = ['oily', 'dry', 'normal']
|
| 13 |
+
|
| 14 |
+
def run():
|
| 15 |
+
# Set judul aplikasi
|
| 16 |
+
st.title('Skin Type Classification')
|
| 17 |
+
st.write('---')
|
| 18 |
+
|
| 19 |
+
# Tambahkan deskripsi
|
| 20 |
+
st.write('Upload an image of skin, and this app will predict the skin type.')
|
| 21 |
+
|
| 22 |
+
# Gambar ilustrasi (opsional)
|
| 23 |
+
link_gambar = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQntnqn33t_1jWqaFszEgEdMCQjGNNtWLxv8A&s' # Ganti dengan URL gambar
|
| 24 |
+
st.image(link_gambar, caption='Know your skin type!', use_container_width=True)
|
| 25 |
+
|
| 26 |
+
# Form untuk upload gambar
|
| 27 |
+
uploaded_file = st.file_uploader('Upload an image:', type=['jpg', 'png', 'jpeg'])
|
| 28 |
+
|
| 29 |
+
if uploaded_file is not None:
|
| 30 |
+
# Tampilkan gambar yang di-upload
|
| 31 |
+
image = Image.open(uploaded_file)
|
| 32 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 33 |
+
|
| 34 |
+
# Convert gambar ke format yang diterima model
|
| 35 |
+
img_array = np.array(image)
|
| 36 |
+
img_resized = cv2.resize(img_array, (220, 220)) # Ubah ukuran ke input model
|
| 37 |
+
img_normalized = img_resized / 255.0 # Normalisasi
|
| 38 |
+
img_expanded = np.expand_dims(img_normalized, axis=0) # Tambahkan batch dimension
|
| 39 |
+
|
| 40 |
+
# Prediksi menggunakan model
|
| 41 |
+
prediction = model.predict(img_expanded)
|
| 42 |
+
predicted_class = CLASS_NAMES[np.argmax(prediction)]
|
| 43 |
+
confidence = np.max(prediction) * 100
|
| 44 |
+
|
| 45 |
+
# Tampilkan hasil prediksi
|
| 46 |
+
st.write(f"### Predicted Skin Type: {predicted_class}")
|
| 47 |
+
st.write(f"### Confidence: {confidence:.2f}%")
|
| 48 |
+
|
| 49 |
+
else:
|
| 50 |
+
st.write('Please upload an image to get a prediction.')
|
| 51 |
+
|
| 52 |
+
if __name__ == '__main__':
|
| 53 |
+
run()
|