Team Ai
Apppublic

panjiputra-r/ComputerVisionPrediction

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
prediction.py48 linesDownload Raw Back to root
1#import library2import pandas as pd3import numpy as np4import streamlit as st5from tensorflow.keras.preprocessing.image import load_img, img_to_array6import matplotlib.pyplot as plt7from PIL import Image8import tensorflow as tf9from tensorflow.keras.models import load_model10 11#import pickle12import pickle13 14#load model15def run():16    file = st.file_uploader("Upload an image", type=["jpg", "png"])17 18    model = tf.keras.models.load_model('model_transfer.keras')19    target_size=(224, 224)20 21    def import_and_predict(image_data, model):22        image = tf.keras.utils.load_img(image_data, target_size=(224, 224))23        x = tf.keras.utils.img_to_array(image)24        x = np.expand_dims(x, axis=0)25 26        plt.imshow(image)27        plt.axis('off')28        plt.show()29 30        # Make prediction31        classes = model.predict(x)32        result_pred = np.where(classes < 0.7, 0, 1)33        if result_pred == 1:34            result = 'Brain Tumor'35        else:36            result = 'Healthy'37 38        return f"Prediction: {result}"39 40    if file is None:41        st.text("Please upload an image file")42    else:43        result = import_and_predict(file, model)44        st.image(file)45        st.write(result)46        47if __name__ == "__main__":48    run()