Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,13 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
from tensorflow_hub.keras_layer import KerasLayer
|
| 5 |
-
from tensorflow.keras.models import load_model
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import tensorflow as tf
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
def load_skin_model():
|
| 12 |
-
return load_model('model_aug.keras', custom_objects={'KerasLayer': KerasLayer})
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def preprocess_image(uploaded_file):
|
| 20 |
-
"""Preprocess the uploaded image for prediction."""
|
| 21 |
-
image = Image.open(uploaded_file).convert("RGB") # Open image and ensure RGB format
|
| 22 |
-
img_array = img_to_array(image) # Convert to NumPy array
|
| 23 |
-
img_resized = tf.image.resize(img_array, [220, 220]) # Resize to model input size
|
| 24 |
-
img_normalized = img_resized / 255.0 # Normalize pixel values
|
| 25 |
-
return tf.expand_dims(img_normalized, axis=0) # Add batch dimension
|
| 26 |
-
|
| 27 |
-
def predict_skin_type(image_data):
|
| 28 |
-
"""Predict the skin type based on the input image."""
|
| 29 |
-
processed_image = preprocess_image(image_data)
|
| 30 |
-
predictions = model.predict(processed_image)
|
| 31 |
-
predicted_class = CLASS_NAMES[np.argmax(predictions)]
|
| 32 |
-
confidence = np.max(predictions) * 100
|
| 33 |
-
return predicted_class, confidence
|
| 34 |
-
|
| 35 |
-
def run():
|
| 36 |
-
st.image('https://i.ytimg.com/vi/Y7nGCB3S5Ww/maxresdefault.jpg', use_container_width=True)
|
| 37 |
-
st.title("Skin Type Prediction Model")
|
| 38 |
-
st.write("Upload an image to know your skin type!")
|
| 39 |
-
|
| 40 |
-
# Upload image
|
| 41 |
-
file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
| 42 |
-
|
| 43 |
-
if file is not None:
|
| 44 |
-
# Display the uploaded image
|
| 45 |
-
st.image(file, caption="Uploaded Image", use_column_width=True)
|
| 46 |
-
|
| 47 |
-
# Predict
|
| 48 |
-
predicted_class, confidence = predict_skin_type(file)
|
| 49 |
-
st.write(f"### Predicted Skin Type: {predicted_class}")
|
| 50 |
-
st.write(f"### Confidence: {confidence:.2f}%")
|
| 51 |
-
else:
|
| 52 |
-
st.write("Please upload an image to get predictions.")
|
| 53 |
-
|
| 54 |
-
if __name__ == "__main__":
|
| 55 |
-
run()
|
|
|
|
| 1 |
+
#import libraries
|
| 2 |
import streamlit as st
|
| 3 |
+
import eda
|
| 4 |
+
import prediction
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
#navigation
|
| 7 |
+
navigation = st.sidebar.selectbox('Choose Page: ', ('Predictor', 'EDA'))
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
#pilih page
|
| 10 |
+
if navigation == 'Predictor':
|
| 11 |
+
prediction.run()
|
| 12 |
+
else:
|
| 13 |
+
eda.run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|