Spaces:
Paused
Paused
Upload 2 files
Browse files12 unmodified lines1314151617181912 unmodified lines# CheXVision GradioA polished, responsive Gradio interface inspired by the CheXVision chest X-rayclassification demo. It includes image upload, examples, model selection,normal/abnormal screening confidence, ranked NIH ChestX-ray14 findings, and avisual explanation panel.12 unmodified lines1314151617181912 unmodified lines# CheXVision GradioA polished, responsive Gradio interface inspired by the CheXVision chest X-rayclassification demo. It includes image upload, model selection,normal/abnormal screening confidence, ranked NIH ChestX-ray14 findings, and avisual explanation panel.
1234567891011121311 unmodified lines252627282930313233345 unmodified lines40414243444546474849505152535455565758596061626364656667686970717273747576777838 unmodified lines11711811912012112212312412580 unmodified lines206207208209210211212213from __future__ import annotationsimport hashlibimport mathimport osfrom pathlib import Pathimport gradio as grimport numpy as npfrom PIL import Image, ImageDraw, ImageEnhance, ImageFiltertry:import spaces11 unmodified linesspaces = _SpacesFallback()APP_DIR = Path(__file__).parentASSET_DIR = APP_DIR / "assets"ASSET_DIR.mkdir(exist_ok=True)FINDINGS = ["Atelectasis", "Cardiomegaly", "Effusion", "Infiltration", "Mass","Nodule", "Pneumonia", "Pneumothorax", "Consolidation", "Edema",5 unmodified lines}def _make_example(path: Path, variant: int) -> None:"""Create small, license-free X-ray-like placeholders for the examples tray."""if path.exists():returnsize = 640yy, xx = np.mgrid[:size, :size]cx, cy = size / 2, size * .47body = np.exp(-(((xx - cx) / 250) ** 2 + ((yy - cy) / 330) ** 2))lungs = (np.exp(-(((xx - 225) / 112) ** 2 + ((yy - 315) / 220) ** 2))+ np.exp(-(((xx - 415) / 112) ** 2 + ((yy - 315) / 220) ** 2)))spine = np.exp(-((xx - cx) / 19) ** 2) * np.exp(-((yy - 330) / 270) ** 2)heart = np.exp(-(((xx - 352) / 100) ** 2 + ((yy - 410) / 115) ** 2))ribs = np.zeros_like(body)for offset in range(-170, 181, 38):curve = 210 + 0.0017 * (xx - cx) ** 2 + offsetribs += np.exp(-((yy - curve) / 3.5) ** 2) * (xx > 90) * (xx < 550)img = 32 + 155 * body - 58 * lungs + 30 * spine + 22 * heart + 17 * ribsif variant == 1:img += 43 * np.exp(-(((xx - 420) / 82) ** 2 + ((yy - 390) / 95) ** 2))elif variant == 2:img += 36 * np.exp(-(((xx - 245) / 120) ** 2 + ((yy - 470) / 58) ** 2))rng = np.random.default_rng(variant + 41)img += rng.normal(0, 3.5, img.shape)Image.fromarray(np.uint8(np.clip(img, 0, 255)), "L").convert("RGB").save(path)EXAMPLES = [ASSET_DIR / f"example_{i}.png" for i in range(3)]for _i, _path in enumerate(EXAMPLES):_make_example(_path, _i)def _prepare(image: Image.Image) -> Image.Image:image = image.convert("L")image = ImageEnhance.Contrast(image).enhance(1.15)38 unmodified linesdef _result_html(scores: np.ndarray) -> str:top = np.argsort(scores)[::-1][:5]rows = []for i in top:pct = float(scores[i] * 100)rows.append(f'<div class="finding-row"><div><span>{FINDINGS[i]}</span>'80 unmodified linestype="pil", sources=["upload", "clipboard"], show_label=False,elem_id="xray-input", height=350,)gr.Markdown("**Or try an example**")gr.Examples(examples=[[str(p)] for p in EXAMPLES], inputs=image_input, label="")gr.HTML('<div class="step" style="margin-top:18px">Step 2</div>')model = gr.Dropdown(choices=list(MODELS), value=list(MODELS)[0], label="Analysis model",123456789101111 unmodified lines2324252627285 unmodified lines34353637383938 unmodified lines78798081828384858680 unmodified lines167168169170171172from __future__ import annotationsimport hashlibimport osimport gradio as grimport numpy as npfrom PIL import Image, ImageEnhance, ImageFiltertry:import spaces11 unmodified linesspaces = _SpacesFallback()FINDINGS = ["Atelectasis", "Cardiomegaly", "Effusion", "Infiltration", "Mass","Nodule", "Pneumonia", "Pneumothorax", "Consolidation", "Edema",5 unmodified lines}def _prepare(image: Image.Image) -> Image.Image:image = image.convert("L")image = ImageEnhance.Contrast(image).enhance(1.15)38 unmodified linesdef _result_html(scores: np.ndarray) -> str:ranked = np.argsort(scores)[::-1]rows = []for i in ranked:pct = float(scores[i] * 100)rows.append(f'<div class="finding-row"><div><span>{FINDINGS[i]}</span>'80 unmodified linestype="pil", sources=["upload", "clipboard"], show_label=False,elem_id="xray-input", height=350,)gr.HTML('<div class="step" style="margin-top:18px">Step 2</div>')model = gr.Dropdown(choices=list(MODELS), value=list(MODELS)[0], label="Analysis model",
README.md+1-1
app.py+3-44