drkareemkamal commited on
Commit
bfbcdca
·
verified ·
1 Parent(s): 425d19f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import os
5
+
6
+ model = tf.keras.models.load_model('Brain_tumor/')
7
+ st.write('Model is loaded successfully')
8
+
9
+ TEMP_DIR = 'temp'
10
+ if not os.path.exists(TEMP_DIR):
11
+ os.makedirs(TEMP_DIR)
12
+
13
+ class_names = ['glioma', 'meningioma', 'notumor', 'pituitary']
14
+
15
+ def load_and_prep_imgg(filename, img_shape=229, scale=True):
16
+ img = tf.io.read_file(filename)
17
+ img = tf.io.decode_image(img)
18
+ img = tf.image.resize(img, size=[img_shape, img_shape])
19
+ if scale:
20
+ return img / 255
21
+ else:
22
+ return img
23
+
24
+ st.title('Brain Tumor Classification Prediction using Xception ImageNet')
25
+
26
+ uploaded_file = st.sidebar.file_uploader('Upload your Image', type=['jpg'])
27
+
28
+ if uploaded_file:
29
+ file_path = os.path.join(TEMP_DIR, uploaded_file.name)
30
+
31
+ # Save the uploaded file to the temporary directory
32
+ with open(file_path, "wb") as f:
33
+ f.write(uploaded_file.getbuffer())
34
+
35
+ img = load_and_prep_imgg(file_path, scale=True)
36
+ imgg = Image.open(file_path)
37
+ st.image(imgg, caption="Uploaded Image")
38
+
39
+ pred_img = model.predict(tf.expand_dims(img, axis=0))
40
+ pred_class = class_names[pred_img.argmax()]
41
+ st.write(f"Predicted brain tumor is: {pred_class} with probability: {pred_img.max():.2f}")