Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions XRay-Pneumonia-Detection-App/main-GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from kivy.clock import Clock
from kivy.uix.image import Image
from kivymd.uix.filemanager import MDFileManager
from kivymd.uix.snackbar import Snackbar
from kivymd.uix.snackbar import MDSnackbar
from kivymd.uix.label import MDLabel
from kivy.lang import Builder

# Other necessary Python modules
Expand All @@ -30,6 +31,7 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self._color_yellow_ = [1, 0.85, 0.25, 1]


class LoadingLayout(MDRelativeLayout):
pass

Expand Down Expand Up @@ -111,8 +113,8 @@ def get_global_path(local_path):
Window.size = (self.window_width, self.window_height)

except Exception as err:
# Show a Snackbar and print the error if there's any issue with the configuration file
Snackbar(text=f"ERROR| {err}").open()
# Show a MDSnackbar and print the error if there's any issue with the configuration file
MDSnackbar(MDLabel(text=f"ERROR| {err}")).open()
print(f"There is an error: {err}")

# Set default window size if there's an error
Expand Down Expand Up @@ -172,7 +174,7 @@ def on_file_selected(self, instance, selection, a, b):
":ERROR| PROBABLY, cannot load an image. Ensure image has a correct format.")
print(f"There is an error: {err}")

Snackbar(text=f"ERROR| {err}").open()
MDSnackbar(MDLabel(text=f"ERROR| {err}")).open()

self.analyzeImage()

Expand Down Expand Up @@ -216,12 +218,12 @@ def probaFeedback(proba):
self.predicted_pneumonia_proba)
self.myIds["_label_class_"].text = str(self.predicted_class)

Snackbar(
text=f"SUCCESS| Image loaded FROM {self.absolute_image_path}").open()
MDSnackbar(
MDLabel(text=f"SUCCESS| Image loaded FROM {self.absolute_image_path}")).open()

except Exception as err:
print(f"There is an error: {err}")
Snackbar(text=f"ERROR| {err}").open()
MDSnackbar(MDLabel(text=f"ERROR| {err}")).open()

# Method to show model information layout (button event)
def btnModelInfo(self, instance=None):
Expand All @@ -243,7 +245,7 @@ def btnModelInfo(self, instance=None):

except Exception as err:
print(f"There is an error: {err}")
Snackbar(text=f"ERROR| {err}").open()
MDSnackbar(MDLabel(text=f"ERROR| {err}")).open()

self.changeCurrentWindow(self.model_info_layout)

Expand All @@ -268,14 +270,13 @@ def show_file_manager(instance=None):
def exit_manager(*args):
self.file_manager.close()
os.remove(self.exportFilename)


def select_path(path):
if path:
save_path = os.path.join(path, self.exportFilename)
self.image_widget.export_to_png(save_path)
path_snackbar = Snackbar(
text=f"SUCCESS| Image saved AS {save_path}").open()
path_snackbar = MDSnackbar(
MDLabel(text=f"SUCCESS| Image saved AS {save_path}")).open()
exit_manager()

try:
Expand All @@ -293,12 +294,12 @@ def select_path(path):
show_file_manager()

except Exception as err:
Snackbar(text=f"ERROR| {err}").open()
MDSnackbar(MDLabel(text=f"ERROR| {err}")).open()
print(f"There is an error: {err}")

# Method to export the results of image analysis (button event)
def btnExportResults(self, instance=None):
self.current_date = self.modules_datetime.datetime.now().strftime("%d-%m-%Y_%H:%M:%S")
self.current_date = self.modules_datetime.datetime.now().strftime("%d-%m-%Y_%H%M%S")

try:

Expand All @@ -321,10 +322,10 @@ def btnExportResults(self, instance=None):

except Exception as err:
print(f"No Image Loaded OR error is {err}")
Snackbar(text=f"ERROR| {err}").open()

MDSnackbar(MDLabel(text=f"ERROR| {err}")).open()

# Method to draw a text data on the image

def exportPNG(self, img_array, notes):
text_canvas = self.modules_np.zeros(
shape=img_array.shape, dtype=img_array.dtype)
Expand Down Expand Up @@ -353,14 +354,14 @@ def add_multiline_notes_to_image(img, notes):
ready_image = self.modules_np.vstack((img_array, text_canvas))

return ready_image


# Entry point of the application
if __name__ == "__main__":
# Run the Kivy App
kivy_app = PneumoniaDetectionApp()
kivy_app.run()

try:
os.remove(kivy_app.exportFilename)
except:
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy
matplotlib
tensorflow
opencv-python
kivy
kivymd==1.2.0