|
import streamlit as st |
|
from tensorflow.keras.models import load_model |
|
import numpy as np |
|
import cv2 |
|
|
|
|
|
|
|
|
|
model = load_model('cancer_model.h5') |
|
class_names= ['adenocarcinoma', 'large cell carcinoma', 'normal', 'squamous cell carcinoma'] |
|
|
|
def predict(image): |
|
|
|
image = cv2.resize(image, (460, 460)) |
|
image = image.astype('float32') / 255.0 |
|
image = image[np.newaxis, :] |
|
|
|
|
|
predictions = model.predict(image) |
|
|
|
|
|
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: |
|
|
|
image = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), 1) |
|
|
|
|
|
st.image(image, caption='Uploaded Image', use_column_width=True) |
|
|
|
|
|
prediction = predict(image) |
|
st.write('Prediction:', prediction) |
|
|