Azrieldr
commited on
Commit
β’
36d49ad
1
Parent(s):
48829e9
initial commit
Browse files- Prediction.py +42 -0
- app.py +17 -0
- cancer_model.h5 +3 -0
Prediction.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import numpy as np
|
4 |
+
import cv2
|
5 |
+
|
6 |
+
|
7 |
+
# Load the Models
|
8 |
+
|
9 |
+
model = load_model('cancer_model.h5')
|
10 |
+
class_names= ['adenocarcinoma', 'large cell carcinoma', 'normal', 'squamous cell carcinoma']
|
11 |
+
|
12 |
+
def predict(image):
|
13 |
+
# Preprocess the image
|
14 |
+
image = cv2.resize(image, (460, 460))
|
15 |
+
image = image.astype('float32') / 255.0
|
16 |
+
image = image[np.newaxis, :]
|
17 |
+
|
18 |
+
# Make predictions
|
19 |
+
predictions = model.predict(image)
|
20 |
+
|
21 |
+
# Get the predicted class name
|
22 |
+
predicted_class_index = np.argmax(predictions[0])
|
23 |
+
predicted_class_name = class_names[predicted_class_index]
|
24 |
+
|
25 |
+
return predicted_class_name
|
26 |
+
|
27 |
+
|
28 |
+
def app():
|
29 |
+
st.title('CNN Image Classifier')
|
30 |
+
|
31 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
32 |
+
|
33 |
+
if uploaded_file is not None:
|
34 |
+
# Read the uploaded image
|
35 |
+
image = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), 1)
|
36 |
+
|
37 |
+
# Display the uploaded image
|
38 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
39 |
+
|
40 |
+
# Make predictions and display the result
|
41 |
+
prediction = predict(image)
|
42 |
+
st.write('Prediction:', prediction)
|
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from Prediction import app as prediction_app
|
3 |
+
|
4 |
+
|
5 |
+
# Define the Streamlit app
|
6 |
+
st.set_page_config(page_title='Image Classifier', page_icon='π')
|
7 |
+
|
8 |
+
PAGES = {
|
9 |
+
'Prediction': prediction_app,
|
10 |
+
}
|
11 |
+
|
12 |
+
st.sidebar.title('Navigation')
|
13 |
+
selection = st.sidebar.radio('Go to', list(PAGES.keys()))
|
14 |
+
|
15 |
+
# Display the selected page with the session state
|
16 |
+
page = PAGES[selection]
|
17 |
+
page()
|
cancer_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c3f8965e5dbb3f99babbad7ceb54a8ec630d9b1918f1a16bb2651cdafeb73369
|
3 |
+
size 217814528
|