M2P2 / Prediction.py
Azrieldr's picture
Editing type of file that can be uploaded
82a6a50
import streamlit as st
from tensorflow.keras.models import load_model
import numpy as np
import cv2
# Load the Models
model = load_model('cancer_model.h5')
class_names= ['adenocarcinoma', 'large cell carcinoma', 'normal', 'squamous cell carcinoma']
def predict(image):
# Preprocess the image
image = cv2.resize(image, (460, 460))
image = image.astype('float32') / 255.0
image = image[np.newaxis, :]
# Make predictions
predictions = model.predict(image)
# Get the predicted class name
predicted_class_index = np.argmax(predictions[0])
predicted_class_name = class_names[predicted_class_index]
return predicted_class_name
def app():
st.title('CNN Image Classifier')
uploaded_file = st.file_uploader("Choose an image...", type=['jpg', 'jpeg', 'png'])
if uploaded_file is not None:
# Read the uploaded image
image = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), 1)
# Display the uploaded image
st.image(image, caption='Uploaded Image', use_column_width=True)
# Make predictions and display the result
prediction = predict(image)
st.write('Prediction:', prediction)