From 515307e73f801f4438c467d26cfb2aa46c2815bc Mon Sep 17 00:00:00 2001 From: Jai Dhingra Date: Wed, 9 Oct 2024 22:54:42 +0530 Subject: [PATCH] Fixed Brain Tumor --- .../BrainTumorModel/brainTumorModel.py | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/apps/pages/models/HealthCareModels/BrainTumorModel/brainTumorModel.py b/src/apps/pages/models/HealthCareModels/BrainTumorModel/brainTumorModel.py index 152bdceb..8dfcd7b0 100644 --- a/src/apps/pages/models/HealthCareModels/BrainTumorModel/brainTumorModel.py +++ b/src/apps/pages/models/HealthCareModels/BrainTumorModel/brainTumorModel.py @@ -6,47 +6,48 @@ @st.cache_resource def load_model(): - model = tf.keras.models.load_model("src/apps/pages/models/HealthCareModels/BrainTumorModel/brain_tumor_test.keras") - return model + model = tf.keras.models.load_model("src/apps/pages/models/HealthCareModels/BrainTumorModel/brain_tumor_test.keras") + return model def get_mri(): - img = st.file_uploader("Upload here",type=["jpg","jpeg"]) - codn = False - data = [] - if img is not None: - st.image(img,width=420,caption="Uploaded Img") - data = Image.open(img).convert("RGB" ) - data = data.resize((64,64)) - data = np.asarray(data) - data = np.expand_dims(data,axis=0) - codn = True - - return codn,data + img = st.file_uploader("Upload here", type=["jpg", "jpeg"]) + codn = False + data = [] + if img is not None: + st.image(img, width=420, caption="Uploaded Img") + data = Image.open(img).convert("RGB") + data = data.resize((64, 64)) + data = np.asarray(data) + data = np.expand_dims(data, axis=0) + codn = True + + return codn, data def do_test(img): - model = load_model() - res = np.argmax(model.predict(img)) - return res + model = load_model() + res = np.argmax(model.predict(img)) + return res def brainTumorModel(): - st.write("Please Upload MRI Scan of Brain") - codn,img = get_mri() - res = None - - if codn!=False: - res = do_test(img) - - if res!=None: - if res == 0: - st.error(f'Hi {st.session_state.name},\nYou are diagnosed with Glioma.\nPlease consult a doctor.') - Speak(f'Hi {st.session_state.name},You are diagnosed with Glioma. Please consult a doctor.') - elif res == 1: - st.error(f'Hi {st.session_state.name},\nYou are diagnosed with Meningioma.\nPlease consult a doctor.') - Speak(f'Hi {st.session_state.name},You are diagnosed with Meningioma. Please consult a doctor.') - elif res == 2: - st.success(f'Congrats {st.session_state.name}, You are not diagnosed with brain tumor.') - Speak(f'Congrats {st.session_state.name}, You are not diagnosed with brain tumor.') - elif res == 3: - st.error(f'Hi {st.session_state.name},\nYou are diagnosed with Pituitary tumor. Please consult a doctor.') - Speak(f'Hi {st.session_state.name},You are diagnosed with Pituitary tumor. Please consult a doctor.') + st.write("Please Upload MRI Scan of Brain") + codn, img = get_mri() + res = None + + if codn: + res = do_test(img) + + if res is not None: + if res == 0: + st.error("Hi User, You are diagnosed with Glioma. Please consult a doctor.") + Speak("Hi User, You are diagnosed with Glioma. Please consult a doctor.") + elif res == 1: + st.error("Hi User, You are diagnosed with Meningioma. Please consult a doctor.") + Speak("Hi User, You are diagnosed with Meningioma. Please consult a doctor.") + elif res == 2: + st.success("Congrats User, You are not diagnosed with a brain tumor.") + Speak("Congrats User, You are not diagnosed with a brain tumor.") + elif res == 3: + st.error("Hi User, You are diagnosed with Pituitary tumor. Please consult a doctor.") + Speak("Hi User, You are diagnosed with Pituitary tumor. Please consult a doctor.") + codn = False