CoolFace
Apppublic

Mathildatambun28/MILESTONE2PHASE2

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app_3.py56 linesDownload Raw Back to root
1import streamlit as st2import tensorflow as tf3import numpy as np4from PIL import Image5from tensorflow.keras.models import load_model6 7st.set_page_config(8    page_title='Predict',9    layout='wide',10    initial_sidebar_state='expanded'11)12 13#load model14best_model = load_model('model2.h5')15 16 17def img_predict(img, model):18    pred = np.array(img)[:, :, :3]19    pred = tf.image.resize(pred, size=(240, 240))20    pred = pred / 255.021 22    23    predicted_probabilities = model.predict(x=tf.expand_dims(pred, axis=0))[0]24 25    26    predicted_class_index = np.argmax(predicted_probabilities)27 28    29    if predicted_class_index == 0:30        return "benign"31    else:32        return "malignant"33 34 35 36 37    38 39def run():40    # variable image41    img = None42 43    # Image upload and prediction44    uploaded_img = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])45 46    if uploaded_img is not None:47        img = Image.open(uploaded_img)48        prediction = img_predict(img, best_model)49 50        # Display the prediction result51        title = f"<h2 style='text-align:center'>{prediction}</h2>"52        st.markdown(title, unsafe_allow_html=True)53        st.image(img, use_column_width=True)54 55if __name__ == "__main__":56    run()