Update app.py
Browse files
app.py
CHANGED
|
@@ -113,7 +113,7 @@ class DicomAnalyzer:
|
|
| 113 |
(display_x, display_y),
|
| 114 |
display_diameter // 2,
|
| 115 |
(0, 255, 255), # Yellow in BGR
|
| 116 |
-
|
| 117 |
lineType=cv2.LINE_AA)
|
| 118 |
|
| 119 |
# Extract visible portion
|
|
@@ -130,6 +130,7 @@ class DicomAnalyzer:
|
|
| 130 |
def handle_keyboard(self, key):
|
| 131 |
"""Handle keyboard inputs for pan"""
|
| 132 |
try:
|
|
|
|
| 133 |
# Pan amount depends on zoom level
|
| 134 |
pan_amount = int(20 * self.zoom_factor)
|
| 135 |
|
|
@@ -274,7 +275,7 @@ def create_interface():
|
|
| 274 |
|
| 275 |
results_display = gr.Textbox(label="Results", interactive=False)
|
| 276 |
file_output = gr.File(label="Download Results")
|
| 277 |
-
key_press = gr.Textbox(visible=False) #
|
| 278 |
|
| 279 |
# Instructions
|
| 280 |
gr.Markdown("""
|
|
@@ -326,8 +327,9 @@ def create_interface():
|
|
| 326 |
|
| 327 |
key_press.change(
|
| 328 |
fn=analyzer.handle_keyboard,
|
| 329 |
-
inputs=
|
| 330 |
-
outputs=
|
|
|
|
| 331 |
)
|
| 332 |
|
| 333 |
blank_btn.click(
|
|
@@ -353,17 +355,19 @@ def create_interface():
|
|
| 353 |
outputs=[file_output, results_display]
|
| 354 |
)
|
| 355 |
|
| 356 |
-
#
|
| 357 |
gr.HTML("""
|
| 358 |
<script>
|
| 359 |
-
function
|
| 360 |
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
| 361 |
e.preventDefault();
|
| 362 |
-
document.querySelector('#key_press textarea')
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
| 364 |
}
|
| 365 |
-
}
|
| 366 |
-
document.addEventListener('keydown', handleKey);
|
| 367 |
</script>
|
| 368 |
""")
|
| 369 |
|
|
|
|
| 113 |
(display_x, display_y),
|
| 114 |
display_diameter // 2,
|
| 115 |
(0, 255, 255), # Yellow in BGR
|
| 116 |
+
2, # Increased thickness
|
| 117 |
lineType=cv2.LINE_AA)
|
| 118 |
|
| 119 |
# Extract visible portion
|
|
|
|
| 130 |
def handle_keyboard(self, key):
|
| 131 |
"""Handle keyboard inputs for pan"""
|
| 132 |
try:
|
| 133 |
+
print(f"Handling key press: {key}") # Debug print
|
| 134 |
# Pan amount depends on zoom level
|
| 135 |
pan_amount = int(20 * self.zoom_factor)
|
| 136 |
|
|
|
|
| 275 |
|
| 276 |
results_display = gr.Textbox(label="Results", interactive=False)
|
| 277 |
file_output = gr.File(label="Download Results")
|
| 278 |
+
key_press = gr.Textbox(visible=False, elem_id="key_press") # Added elem_id
|
| 279 |
|
| 280 |
# Instructions
|
| 281 |
gr.Markdown("""
|
|
|
|
| 327 |
|
| 328 |
key_press.change(
|
| 329 |
fn=analyzer.handle_keyboard,
|
| 330 |
+
inputs=key_press,
|
| 331 |
+
outputs=image_display,
|
| 332 |
+
api_name="handle_keyboard"
|
| 333 |
)
|
| 334 |
|
| 335 |
blank_btn.click(
|
|
|
|
| 355 |
outputs=[file_output, results_display]
|
| 356 |
)
|
| 357 |
|
| 358 |
+
# Updated JavaScript for keyboard handling
|
| 359 |
gr.HTML("""
|
| 360 |
<script>
|
| 361 |
+
document.addEventListener('keydown', function(e) {
|
| 362 |
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
| 363 |
e.preventDefault();
|
| 364 |
+
const keyPressElement = document.querySelector('#key_press textarea');
|
| 365 |
+
if (keyPressElement) {
|
| 366 |
+
keyPressElement.value = e.key;
|
| 367 |
+
keyPressElement.dispatchEvent(new Event('input'));
|
| 368 |
+
}
|
| 369 |
}
|
| 370 |
+
});
|
|
|
|
| 371 |
</script>
|
| 372 |
""")
|
| 373 |
|