Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#import libraries
|
| 2 |
+
import pandas as pd
|
| 3 |
+
impurt numpy as np
|
| 4 |
+
import streamlit as st
|
| 5 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
| 6 |
+
from tensorflow_hub.keras_layer import KerasLayer
|
| 7 |
+
|
| 8 |
+
import tensorflow as tf
|
| 9 |
+
from tensorflow.keras.models import load_model
|
| 10 |
+
|
| 11 |
+
#import pickle
|
| 12 |
+
import pickle
|
| 13 |
+
|
| 14 |
+
#load model
|
| 15 |
+
def run():
|
| 16 |
+
st.image('https://i.ytimg.com/vi/Y7nGCB3S5Ww/maxresdefault.jpg', use_container_width=True)
|
| 17 |
+
st.title("Skin Type Prediction Model")
|
| 18 |
+
st.write("Upload an image to know your skin type!")
|
| 19 |
+
file = st.file_uploader("Upload an image", type=["jpg", "png"])
|
| 20 |
+
|
| 21 |
+
model = load_model('model_aug.keras', custom_objects={'KerasLayer': KerasLayer})
|
| 22 |
+
target_size=(220, 220)
|
| 23 |
+
|
| 24 |
+
def import_and_predict(image_data, model):
|
| 25 |
+
image = load_img(image_data, target_size=(220,220))
|
| 26 |
+
img_array = img_to_array(image)
|
| 27 |
+
img_array = tf.expand_dims(img_array, 0)
|
| 28 |
+
|
| 29 |
+
#Normalize image
|
| 30 |
+
img_array = img_array/255
|
| 31 |
+
|
| 32 |
+
#make prediction
|
| 33 |
+
predictions = model.predict(img_array)
|
| 34 |
+
|
| 35 |
+
#Get class with the highest possibility
|
| 36 |
+
idx = np.where(predictions => 0.5, 1, 0).item()
|
| 37 |
+
|
| 38 |
+
type = ['oily', 'dry', 'normal']
|
| 39 |
+
result = f'Prediction: {type[idx]}'
|
| 40 |
+
|
| 41 |
+
return result
|
| 42 |
+
|
| 43 |
+
if file is None:
|
| 44 |
+
st.text("Please upload in image file")
|
| 45 |
+
else:
|
| 46 |
+
result = import_and_predict(file, model)
|
| 47 |
+
st.image(file)
|
| 48 |
+
st.write(result)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__"
|
| 51 |
+
run
|