Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr, os
|
| 2 |
+
from bootstrap_upstream import fetch_upstream
|
| 3 |
+
from pipeline.rules import zone_lus_score, ZoneFeatures
|
| 4 |
+
from pipeline import rtlucassen_wrapper as rtl
|
| 5 |
+
from pipeline import medivlad_wrapper as mvl
|
| 6 |
+
|
| 7 |
+
def setup_check():
|
| 8 |
+
results = fetch_upstream()
|
| 9 |
+
folders = {
|
| 10 |
+
"B-line_detection": os.path.isdir("external/B-line_detection"),
|
| 11 |
+
"LUS-Segmentation-RT": os.path.isdir("external/LUS-Segmentation-RT"),
|
| 12 |
+
"MeDiVLAD": os.path.isdir("external/MeDiVLAD"),
|
| 13 |
+
"weights_rtlucassen": os.path.isdir("models/rtlucassen"),
|
| 14 |
+
"weights_medivlad": os.path.isdir("models/medivlad"),
|
| 15 |
+
}
|
| 16 |
+
return {"fetched": results, "folders": folders}
|
| 17 |
+
|
| 18 |
+
def score_demo_zone(_clip):
|
| 19 |
+
try:
|
| 20 |
+
b_counts, _ = rtl.run_bline_detector(_clip)
|
| 21 |
+
median_b = sorted(b_counts)[len(b_counts)//2] if b_counts else 0
|
| 22 |
+
z = ZoneFeatures(b_count=median_b, b_area_frac=0.0, has_consolidation=False)
|
| 23 |
+
return {"zone_score": zone_lus_score(z), "median_b": median_b}
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return {"error": str(e)}
|
| 26 |
+
|
| 27 |
+
def run_medivlad(_clip):
|
| 28 |
+
try:
|
| 29 |
+
return mvl.run_video_severity(_clip)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return {"error": str(e)}
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("## NeoLUS — Original Repos (private research)\n**Note:** Upload authorized weights to `/models/*`. Not for clinical use.")
|
| 35 |
+
with gr.Accordion("Setup / Status", open=True):
|
| 36 |
+
gr.Button("Run setup check").click(setup_check, None, gr.JSON())
|
| 37 |
+
|
| 38 |
+
with gr.Tab("Zone Scoring"):
|
| 39 |
+
clip = gr.Video(label="Zone clip")
|
| 40 |
+
go = gr.Button("Analyze zone")
|
| 41 |
+
out = gr.JSON()
|
| 42 |
+
go.click(score_demo_zone, clip, out)
|
| 43 |
+
|
| 44 |
+
with gr.Tab("Video Severity (MeDiVLAD)"):
|
| 45 |
+
clip2 = gr.Video()
|
| 46 |
+
go2 = gr.Button("Run")
|
| 47 |
+
out2 = gr.JSON()
|
| 48 |
+
go2.click(run_medivlad, clip2, out2)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|