Spaces:
Sleeping
Sleeping
| import numpy as np | |
| import os | |
| import cv2 | |
| import tensorflow as tf | |
| import streamlit as st | |
| from tensorflow.keras.models import load_model | |
| st.subheader("Skin Cancer Detection CNN") | |
| print(os.getcwd()) | |
| def load_cached_models(): | |
| model = load_model("Skin Cancer/skin_cancer.keras") | |
| return model | |
| model= load_cached_models() | |
| uploaded_file = st.file_uploader("Upload an X-ray image (JPEG/PNG)", type=["jpeg", "jpg", "png"]) | |
| if uploaded_file is not None: | |
| file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8) | |
| img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR) | |
| img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
| img_resized = cv2.resize(img, (224, 224)).astype('float32') / 255.0 | |
| img_expanded = np.expand_dims(img_resized, axis=0) | |
| pred = model.predict(img_expanded) | |
| pred = pred.flatten()[np.argmax(pred)] | |
| st.image(img, caption="Uploaded X-ray", use_container_width=True) | |
| st.subheader("Prediction") | |
| final_pred = round(float(pred) * 100, 2) | |
| st.progress(int(round(pred * 100))) | |
| st.write(f"### Percentage: {final_pred}%") | |
| st.write("#### Cancer Detected" if pred > 0.5 else "Your Image seems normal") |