Team Ai
Apppublic

rachman/sample_computer_vision

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
streamlit_app.py49 linesDownload Raw Back to src
1#import library2import pandas as pd3import numpy as np4import streamlit as st5from tensorflow.keras.preprocessing.image import load_img, img_to_array6from tensorflow_hub.keras_layer import KerasLayer 7 8import 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 = load_model('src/my_model.keras', custom_objects={'KerasLayer': KerasLayer})19    target_size=(224, 224)20 21    def import_and_predict(image_data, model):22        image = load_img(image_data, target_size=(224, 224))23        img_array = img_to_array(image)24        img_array = tf.expand_dims(img_array, 0)  # Create a batch25 26        # Normalize the image27        img_array = img_array / 255.028 29        # Make prediction30        predictions = model.predict(img_array)31 32        # Get the class with the highest probability33        idx = np.where(predictions >= 0.5, 1, 0).item()34        # predicted_class = np.argmax(predictions)35 36        jenis = ['Brain Tumor', 'Healthy']37        result = f"Prediction: {jenis[idx]}"38 39        return result40 41    if file is None:42        st.text("Please upload an image file")43    else:44        result = import_and_predict(file, model)45        st.image(file)46        st.write(result)47        48if __name__ == "__main__":49    run()