Spaces:
Runtime error
Runtime error
LovnishVerma
commited on
Commit
•
890a9f7
1
Parent(s):
de95601
Update app.py
Browse files
app.py
CHANGED
@@ -47,15 +47,20 @@ def crop_imgs(set_name, add_pixels_value=0):
|
|
47 |
return np.array(set_new)
|
48 |
|
49 |
# Function to preprocess the image
|
50 |
-
def preprocess_image(
|
51 |
-
img = image.load_img(
|
52 |
img_array = image.img_to_array(img)
|
53 |
img_array = np.expand_dims(img_array, axis=0)
|
54 |
img_array /= 255.0 # Normalize the image
|
55 |
return img_array
|
56 |
|
57 |
-
def predict_braintumor(
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
# Crop and preprocess the grayscale image
|
61 |
img_processed = crop_imgs([img_gray])
|
@@ -100,5 +105,10 @@ def main():
|
|
100 |
st.success(result)
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
47 |
return np.array(set_new)
|
48 |
|
49 |
# Function to preprocess the image
|
50 |
+
def preprocess_image(img_path):
|
51 |
+
img = image.load_img(img_path, target_size=(200, 200))
|
52 |
img_array = image.img_to_array(img)
|
53 |
img_array = np.expand_dims(img_array, axis=0)
|
54 |
img_array /= 255.0 # Normalize the image
|
55 |
return img_array
|
56 |
|
57 |
+
def predict_braintumor(img_input):
|
58 |
+
if isinstance(img_input, str): # File path (for Streamlit)
|
59 |
+
img_path = img_input
|
60 |
+
img_gray = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
|
61 |
+
else: # NumPy array (for Gradio)
|
62 |
+
img_array = img_input.astype(np.uint8)
|
63 |
+
img_gray = cv2.cvtColor(img_array, cv2.COLOR_BGR2GRAY)
|
64 |
|
65 |
# Crop and preprocess the grayscale image
|
66 |
img_processed = crop_imgs([img_gray])
|
|
|
105 |
st.success(result)
|
106 |
|
107 |
if __name__ == "__main__":
|
108 |
+
# Streamlit part
|
109 |
+
if "streamlit" in st.__version__.lower():
|
110 |
+
main()
|
111 |
+
|
112 |
+
# Gradio part
|
113 |
+
iface = gr.Interface(fn=predict_braintumor, inputs="image", outputs="text")
|
114 |
+
iface.launch()
|