From aa34fddd851dd19055b3be2f43159f292a8f6aa2 Mon Sep 17 00:00:00 2001 From: HariKiran Date: Fri, 16 Feb 2024 12:37:06 +0530 Subject: [PATCH 1/2] resolved issue with Snackbar in kivymd module by changing the code to wrt v1.2.0 --- XRay-Pneumonia-Detection-App/main-GUI.py | 35 ++++++++++++------------ requirements.txt | 6 ++++ 2 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 requirements.txt diff --git a/XRay-Pneumonia-Detection-App/main-GUI.py b/XRay-Pneumonia-Detection-App/main-GUI.py index d7882c1..53dc096 100644 --- a/XRay-Pneumonia-Detection-App/main-GUI.py +++ b/XRay-Pneumonia-Detection-App/main-GUI.py @@ -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 @@ -30,6 +31,7 @@ def __init__(self, **kwargs): super().__init__(**kwargs) self._color_yellow_ = [1, 0.85, 0.25, 1] + class LoadingLayout(MDRelativeLayout): pass @@ -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 @@ -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() @@ -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): @@ -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) @@ -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: @@ -293,9 +294,9 @@ 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") @@ -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) @@ -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: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6ab14e2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +numpy +matplotlib +tensorflow +opencv-python +kivy +kivymd==1.2.0 \ No newline at end of file From 10b1ab34ce5ba9a5720ebf456adc54afbf13d2ba Mon Sep 17 00:00:00 2001 From: HariKiran Date: Sun, 18 Feb 2024 00:34:00 +0530 Subject: [PATCH 2/2] resolved the issue with img filename when exported --- XRay-Pneumonia-Detection-App/main-GUI.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XRay-Pneumonia-Detection-App/main-GUI.py b/XRay-Pneumonia-Detection-App/main-GUI.py index 53dc096..99c0204 100644 --- a/XRay-Pneumonia-Detection-App/main-GUI.py +++ b/XRay-Pneumonia-Detection-App/main-GUI.py @@ -299,7 +299,7 @@ def select_path(path): # 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: