Spaces:
Runtime error
Runtime error
LovnishVerma
commited on
Commit
•
f1bea19
1
Parent(s):
5bf629c
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import numpy as np
|
|
5 |
from tensorflow.keras.models import load_model
|
6 |
from tensorflow.keras.applications.vgg16 import preprocess_input
|
7 |
from tensorflow.keras.preprocessing import image
|
8 |
-
from werkzeug.utils import secure_filename
|
9 |
import os
|
10 |
|
11 |
# Loading Models
|
@@ -16,9 +15,6 @@ UPLOAD_FOLDER = 'static/uploads'
|
|
16 |
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
17 |
st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
|
18 |
|
19 |
-
def allowed_file(filename):
|
20 |
-
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
21 |
-
|
22 |
def preprocess_imgs(set_name, img_size):
|
23 |
set_new = []
|
24 |
for img in set_name:
|
@@ -58,13 +54,16 @@ def preprocess_image(file_path):
|
|
58 |
def binary_decision(confidence):
|
59 |
return 1 if confidence >= 0.5 else 0
|
60 |
|
61 |
-
def predict_braintumor(
|
62 |
# Save the uploaded file
|
63 |
filename = "temp_image.png"
|
64 |
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
65 |
|
|
|
|
|
|
|
66 |
with open(file_path, "wb") as f:
|
67 |
-
f.write(
|
68 |
|
69 |
img_gray = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
|
70 |
|
@@ -77,7 +76,7 @@ def predict_braintumor(file_contents):
|
|
77 |
|
78 |
# Handle binary decision
|
79 |
confidence = pred[0][0]
|
80 |
-
return binary_decision(confidence)
|
81 |
|
82 |
def main():
|
83 |
st.title("Brain Tumor Prediction App")
|
@@ -89,18 +88,12 @@ def main():
|
|
89 |
st.write("")
|
90 |
st.write("Classifying...")
|
91 |
|
92 |
-
# Read the contents of the uploaded file
|
93 |
-
file_contents = uploaded_file.read()
|
94 |
-
|
95 |
# Make prediction
|
96 |
-
result = predict_braintumor(
|
97 |
|
98 |
# Display prediction
|
99 |
st.subheader("Prediction:")
|
100 |
-
|
101 |
-
st.success("Brain Tumor Found!")
|
102 |
-
else:
|
103 |
-
st.success("Brain Tumor Not Found!")
|
104 |
|
105 |
if __name__ == "__main__":
|
106 |
# Streamlit app
|
|
|
5 |
from tensorflow.keras.models import load_model
|
6 |
from tensorflow.keras.applications.vgg16 import preprocess_input
|
7 |
from tensorflow.keras.preprocessing import image
|
|
|
8 |
import os
|
9 |
|
10 |
# Loading Models
|
|
|
15 |
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
16 |
st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
|
17 |
|
|
|
|
|
|
|
18 |
def preprocess_imgs(set_name, img_size):
|
19 |
set_new = []
|
20 |
for img in set_name:
|
|
|
54 |
def binary_decision(confidence):
|
55 |
return 1 if confidence >= 0.5 else 0
|
56 |
|
57 |
+
def predict_braintumor(img):
|
58 |
# Save the uploaded file
|
59 |
filename = "temp_image.png"
|
60 |
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
61 |
|
62 |
+
# Convert Gradio image data to bytes
|
63 |
+
img_bytes = img.read()
|
64 |
+
|
65 |
with open(file_path, "wb") as f:
|
66 |
+
f.write(img_bytes)
|
67 |
|
68 |
img_gray = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
|
69 |
|
|
|
76 |
|
77 |
# Handle binary decision
|
78 |
confidence = pred[0][0]
|
79 |
+
return "Brain Tumor Found!" if binary_decision(confidence) == 1 else "Brain Tumor Not Found!"
|
80 |
|
81 |
def main():
|
82 |
st.title("Brain Tumor Prediction App")
|
|
|
88 |
st.write("")
|
89 |
st.write("Classifying...")
|
90 |
|
|
|
|
|
|
|
91 |
# Make prediction
|
92 |
+
result = predict_braintumor(uploaded_file)
|
93 |
|
94 |
# Display prediction
|
95 |
st.subheader("Prediction:")
|
96 |
+
st.success(result)
|
|
|
|
|
|
|
97 |
|
98 |
if __name__ == "__main__":
|
99 |
# Streamlit app
|