import streamlit as st from PIL import Image import numpy as np import tensorflow as tf # Hide Streamlit UI elements hide_streamlit_style = """ """ st.markdown(hide_streamlit_style, unsafe_allow_html=True) # Center-align elements st.markdown( """ """, unsafe_allow_html=True ) # Load the HDF5 model model = tf.keras.models.load_model('best_model (1).h5') # Updated to .h5 # Class labels labels = { 0: 'Chickenpox', 1: 'Cowpox', 2: 'HFMD', 3: 'Healthy', 4: 'Measles', 5: 'MPOX' } def preprocess_image(image): image = image.resize((224, 224)) image_array = np.array(image) image_array = np.expand_dims(image_array, axis=0) return image_array def predict(image): processed_image = preprocess_image(image) prediction = model.predict(processed_image) label_index = np.argmax(prediction) predicted_label = labels[label_index] confidence = prediction[0][label_index] * 100 return predicted_label, confidence def main(): st.markdown("

Skin Lesion Classifier

", unsafe_allow_html=True) number = st.radio('Pick one', ['Upload from gallery', 'Capture by camera']) uploaded_file = None if number == 'Capture by camera': uploaded_file = st.camera_input("Take a picture") else: uploaded_file = st.file_uploader("Choose an image", type=["jpg", "png", "jpeg", "bmp"]) if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, caption='Uploaded Image', use_column_width=True) predicted_label, confidence = predict(image) st.markdown("

This might be:

", unsafe_allow_html=True) st.markdown(f"

{predicted_label}

", unsafe_allow_html=True) st.markdown(f"

Confidence: {confidence:.2f}%

", unsafe_allow_html=True) if __name__ == '__main__': main()