nisharg nargund commited on
Commit
08257b6
·
1 Parent(s): 09e53e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import cv2
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ # Load the trained model
8
+ model = tf.keras.models.load_model('braintumor.h5')
9
+
10
+ # Define labels for the classes
11
+ labels = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']
12
+
13
+ # Define a function to make predictions
14
+ def predict_tumor_type(image):
15
+ # Preprocess the image
16
+ img = cv2.resize(image, (150, 150))
17
+ img_array = np.array(img)
18
+ img_array = img_array.reshape(1, 150, 150, 3)
19
+
20
+ # Make prediction
21
+ prediction = model.predict(img_array)
22
+ predicted_class = labels[np.argmax(prediction)]
23
+ confidence = np.max(prediction)
24
+
25
+ return predicted_class, confidence
26
+
27
+ # Streamlit UI
28
+ st.title("Brain Tumor Classification")
29
+ st.write("Upload an image for brain tumor classification.")
30
+
31
+ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
32
+
33
+ if uploaded_image is not None:
34
+ # Display the uploaded image
35
+ image = Image.open(uploaded_image)
36
+ st.image(image, caption="Uploaded Image", use_column_width=True)
37
+
38
+ # Make prediction
39
+ prediction, confidence = predict_tumor_type(np.array(image))
40
+
41
+ st.write("Prediction:", prediction)
42
+ st.write(f"Confidence: {confidence * 100:.2f}%")
43
+
44
+ st.write("DISCLAIMER:")
45
+ st.write("0 - glioma_tumor")
46
+ st.write("1 - meningioma_tumor")
47
+ st.write("2 - No_tumor")
48
+ st.write("3 - pituitary_tumor")