-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
44 lines (36 loc) · 1.27 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
import cv2
import numpy as np
from keras.models import load_model
# Load the trained model
model = load_model('skin_cancer_detection_model.h5')
# Define the size of the input images
img_size = (224, 224)
# Define a function to preprocess the input image
def preprocess_image(img):
img = cv2.resize(img, img_size)
img = np.expand_dims(img, axis=0)
img = img / 255.0
return img
# Define the Streamlit app
def app():
st.title('Skin Cancer Detection App')
# Allow the user to upload an image
uploaded_file = st.file_uploader('Choose an image', type=['jpg', 'jpeg', 'png'])
if uploaded_file is not None:
# Read the image
img = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), 1)
# Display the image
st.image(img, caption='Uploaded Image', use_column_width=True)
# Preprocess the image
img = preprocess_image(img)
# Make a prediction
pred = model.predict(img)
pred_label = 'Cancer' if pred[0][0] > 0.5 else 'Not Cancer'
pred_prob = pred[0][0]
# Show the prediction result
st.write(f'Prediction: {pred_label}')
st.write(f'Probability Of Skin Cancer: {pred_prob:.2f}')
# Run the app
if __name__ == '__main__':
app()