Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ if os.path.exists(MODEL_FILE):
|
|
| 41 |
except Exception as e:
|
| 42 |
print(f"❌ Error loading weights: {e}")
|
| 43 |
else:
|
| 44 |
-
print(f"⚠️ Warning: {MODEL_FILE} not found.
|
| 45 |
|
| 46 |
# ==========================================
|
| 47 |
# 2. SMART FILE HANDLER
|
|
@@ -78,7 +78,6 @@ def find_sequences(file_list):
|
|
| 78 |
|
| 79 |
for path in all_files:
|
| 80 |
fname = os.path.basename(path).lower()
|
| 81 |
-
# Heuristic matching
|
| 82 |
if "dwi" in fname: dwi_path = path
|
| 83 |
elif "adc" in fname: adc_path = path
|
| 84 |
|
|
@@ -89,7 +88,6 @@ def find_sequences(file_list):
|
|
| 89 |
# ==========================================
|
| 90 |
class HandleMissingADCd(MapTransform):
|
| 91 |
def __call__(self, data):
|
| 92 |
-
# If ADC is missing (flagged in data dict), zero it out
|
| 93 |
if data.get("missing_adc", False):
|
| 94 |
data["image"][1] = data["image"][1] * 0.0
|
| 95 |
return data
|
|
@@ -109,6 +107,8 @@ def generate_overlay(original_dwi_path, mask_data):
|
|
| 109 |
"""Visualizes the stroke slice."""
|
| 110 |
img = nib.load(original_dwi_path)
|
| 111 |
dwi_vol = img.get_fdata()
|
|
|
|
|
|
|
| 112 |
dwi_vol = np.rot90(dwi_vol, k=1, axes=(0, 1))
|
| 113 |
mask_vol = np.rot90(mask_data, k=1, axes=(0, 1))
|
| 114 |
|
|
@@ -140,7 +140,6 @@ def segment_stroke(file_list):
|
|
| 140 |
return {"error": "CRITICAL: No DWI sequence found."}, None
|
| 141 |
|
| 142 |
# 2. Prepare Input
|
| 143 |
-
# If ADC is missing, duplicate DWI but flag it for zero-filling
|
| 144 |
img_list = [dwi_path, adc_path] if adc_path else [dwi_path, dwi_path]
|
| 145 |
input_data = {"image": img_list, "missing_adc": not bool(adc_path)}
|
| 146 |
|
|
@@ -183,7 +182,8 @@ def segment_stroke(file_list):
|
|
| 183 |
# ==========================================
|
| 184 |
# 5. GRADIO UI
|
| 185 |
# ==========================================
|
| 186 |
-
|
|
|
|
| 187 |
gr.Markdown("# 👁️ Neuro-Triage: Vision Agent")
|
| 188 |
|
| 189 |
with gr.Row():
|
|
|
|
| 41 |
except Exception as e:
|
| 42 |
print(f"❌ Error loading weights: {e}")
|
| 43 |
else:
|
| 44 |
+
print(f"⚠️ Warning: {MODEL_FILE} not found. Please upload it to Files.")
|
| 45 |
|
| 46 |
# ==========================================
|
| 47 |
# 2. SMART FILE HANDLER
|
|
|
|
| 78 |
|
| 79 |
for path in all_files:
|
| 80 |
fname = os.path.basename(path).lower()
|
|
|
|
| 81 |
if "dwi" in fname: dwi_path = path
|
| 82 |
elif "adc" in fname: adc_path = path
|
| 83 |
|
|
|
|
| 88 |
# ==========================================
|
| 89 |
class HandleMissingADCd(MapTransform):
|
| 90 |
def __call__(self, data):
|
|
|
|
| 91 |
if data.get("missing_adc", False):
|
| 92 |
data["image"][1] = data["image"][1] * 0.0
|
| 93 |
return data
|
|
|
|
| 107 |
"""Visualizes the stroke slice."""
|
| 108 |
img = nib.load(original_dwi_path)
|
| 109 |
dwi_vol = img.get_fdata()
|
| 110 |
+
|
| 111 |
+
# Rotate to standard view if needed
|
| 112 |
dwi_vol = np.rot90(dwi_vol, k=1, axes=(0, 1))
|
| 113 |
mask_vol = np.rot90(mask_data, k=1, axes=(0, 1))
|
| 114 |
|
|
|
|
| 140 |
return {"error": "CRITICAL: No DWI sequence found."}, None
|
| 141 |
|
| 142 |
# 2. Prepare Input
|
|
|
|
| 143 |
img_list = [dwi_path, adc_path] if adc_path else [dwi_path, dwi_path]
|
| 144 |
input_data = {"image": img_list, "missing_adc": not bool(adc_path)}
|
| 145 |
|
|
|
|
| 182 |
# ==========================================
|
| 183 |
# 5. GRADIO UI
|
| 184 |
# ==========================================
|
| 185 |
+
# FIX: Removed 'theme' argument to prevent crash
|
| 186 |
+
with gr.Blocks() as demo:
|
| 187 |
gr.Markdown("# 👁️ Neuro-Triage: Vision Agent")
|
| 188 |
|
| 189 |
with gr.Row():
|