Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import pydicom
|
|
| 6 |
import io
|
| 7 |
from PIL import Image
|
| 8 |
|
|
|
|
|
|
|
| 9 |
class DicomAnalyzer:
|
| 10 |
def __init__(self):
|
| 11 |
self.results = []
|
|
@@ -22,6 +24,7 @@ class DicomAnalyzer:
|
|
| 22 |
self.pan_y = 0
|
| 23 |
self.max_pan_x = 0
|
| 24 |
self.max_pan_y = 0
|
|
|
|
| 25 |
|
| 26 |
def load_dicom(self, file):
|
| 27 |
try:
|
|
@@ -48,9 +51,11 @@ class DicomAnalyzer:
|
|
| 48 |
|
| 49 |
# Reset view on new image
|
| 50 |
self.reset_view()
|
|
|
|
| 51 |
|
| 52 |
return self.display_image, "DICOM file loaded successfully"
|
| 53 |
except Exception as e:
|
|
|
|
| 54 |
return None, f"Error loading DICOM file: {str(e)}"
|
| 55 |
|
| 56 |
def normalize_image(self, image):
|
|
@@ -72,10 +77,12 @@ class DicomAnalyzer:
|
|
| 72 |
return None
|
| 73 |
|
| 74 |
def zoom_in(self, image):
|
|
|
|
| 75 |
self.zoom_factor = min(20.0, self.zoom_factor + 0.5)
|
| 76 |
return self.update_display()
|
| 77 |
|
| 78 |
def zoom_out(self, image):
|
|
|
|
| 79 |
self.zoom_factor = max(1.0, self.zoom_factor - 0.5)
|
| 80 |
return self.update_display()
|
| 81 |
|
|
@@ -177,6 +184,7 @@ class DicomAnalyzer:
|
|
| 177 |
}
|
| 178 |
self.results.append(result)
|
| 179 |
self.marks.append((x, y, self.circle_diameter))
|
|
|
|
| 180 |
|
| 181 |
return self.update_display(), self.format_results()
|
| 182 |
except Exception as e:
|
|
@@ -237,6 +245,7 @@ class DicomAnalyzer:
|
|
| 237 |
return None, f"Error saving results: {str(e)}"
|
| 238 |
|
| 239 |
def create_interface():
|
|
|
|
| 240 |
analyzer = DicomAnalyzer()
|
| 241 |
|
| 242 |
with gr.Blocks(css="#image_display { outline: none; }") as interface:
|
|
@@ -280,6 +289,7 @@ def create_interface():
|
|
| 280 |
|
| 281 |
def update_diameter(x):
|
| 282 |
analyzer.circle_diameter = x
|
|
|
|
| 283 |
return f"Diameter set to {x} pixels"
|
| 284 |
|
| 285 |
# Event handlers
|
|
@@ -362,4 +372,20 @@ def create_interface():
|
|
| 362 |
"""
|
| 363 |
gr.HTML(js)
|
| 364 |
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import io
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
+
print("Starting imports completed...")
|
| 10 |
+
|
| 11 |
class DicomAnalyzer:
|
| 12 |
def __init__(self):
|
| 13 |
self.results = []
|
|
|
|
| 24 |
self.pan_y = 0
|
| 25 |
self.max_pan_x = 0
|
| 26 |
self.max_pan_y = 0
|
| 27 |
+
print("DicomAnalyzer initialized...")
|
| 28 |
|
| 29 |
def load_dicom(self, file):
|
| 30 |
try:
|
|
|
|
| 51 |
|
| 52 |
# Reset view on new image
|
| 53 |
self.reset_view()
|
| 54 |
+
print("DICOM file loaded successfully")
|
| 55 |
|
| 56 |
return self.display_image, "DICOM file loaded successfully"
|
| 57 |
except Exception as e:
|
| 58 |
+
print(f"Error loading DICOM file: {str(e)}")
|
| 59 |
return None, f"Error loading DICOM file: {str(e)}"
|
| 60 |
|
| 61 |
def normalize_image(self, image):
|
|
|
|
| 77 |
return None
|
| 78 |
|
| 79 |
def zoom_in(self, image):
|
| 80 |
+
print("Zooming in...")
|
| 81 |
self.zoom_factor = min(20.0, self.zoom_factor + 0.5)
|
| 82 |
return self.update_display()
|
| 83 |
|
| 84 |
def zoom_out(self, image):
|
| 85 |
+
print("Zooming out...")
|
| 86 |
self.zoom_factor = max(1.0, self.zoom_factor - 0.5)
|
| 87 |
return self.update_display()
|
| 88 |
|
|
|
|
| 184 |
}
|
| 185 |
self.results.append(result)
|
| 186 |
self.marks.append((x, y, self.circle_diameter))
|
| 187 |
+
print(f"ROI analyzed at point ({x}, {y})")
|
| 188 |
|
| 189 |
return self.update_display(), self.format_results()
|
| 190 |
except Exception as e:
|
|
|
|
| 245 |
return None, f"Error saving results: {str(e)}"
|
| 246 |
|
| 247 |
def create_interface():
|
| 248 |
+
print("Creating interface...")
|
| 249 |
analyzer = DicomAnalyzer()
|
| 250 |
|
| 251 |
with gr.Blocks(css="#image_display { outline: none; }") as interface:
|
|
|
|
| 289 |
|
| 290 |
def update_diameter(x):
|
| 291 |
analyzer.circle_diameter = x
|
| 292 |
+
print(f"Diameter updated to: {x}")
|
| 293 |
return f"Diameter set to {x} pixels"
|
| 294 |
|
| 295 |
# Event handlers
|
|
|
|
| 372 |
"""
|
| 373 |
gr.HTML(js)
|
| 374 |
|
| 375 |
+
print("Interface created successfully")
|
| 376 |
+
return interface
|
| 377 |
+
|
| 378 |
+
if __name__ == "__main__":
|
| 379 |
+
try:
|
| 380 |
+
print("Starting application...")
|
| 381 |
+
interface = create_interface()
|
| 382 |
+
print("Launching interface...")
|
| 383 |
+
interface.launch(
|
| 384 |
+
server_name="0.0.0.0",
|
| 385 |
+
server_port=7860,
|
| 386 |
+
share=True,
|
| 387 |
+
debug=True
|
| 388 |
+
)
|
| 389 |
+
except Exception as e:
|
| 390 |
+
print(f"Error launching application: {str(e)}")
|
| 391 |
+
raise e
|