cfoli commited on
Commit
6bcaa34
·
1 Parent(s): a08e4df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -7,10 +7,6 @@ Original file is located at
7
  https://colab.research.google.com/drive/1gVrx5TyipNPvn8D7GaK0pNBCnLeYTAD_
8
  """
9
 
10
- !pip install --upgrade gradio
11
-
12
- !pip install lightning torchmetrics
13
-
14
  """### Import dependencies"""
15
 
16
  import torch
@@ -256,8 +252,8 @@ def run_diagnosis(
256
  x = preprocess_fn(input_image).unsqueeze(0)
257
 
258
  # Resolve backbone
259
- backbone_info = MODEL_REGISTRY[backbone_name]
260
- ckpt_path = os.path.join(CKPT_ROOT, backbone_info["ckpt"])
261
 
262
  if not os.path.exists(ckpt_path):
263
  raise FileNotFoundError(f"Checkpoint not found: {ckpt_path}")
@@ -265,7 +261,7 @@ def run_diagnosis(
265
  # Load model (cache for speed)
266
  if backbone_name not in MODEL_CACHE:
267
  MODEL_CACHE[backbone_name] = modelModule.load_from_checkpoint(
268
- ckpt_path, backbone_model_name=backbone_info["torchvision_name"], num_layers_to_unfreeze = 2)
269
  model = MODEL_CACHE[backbone_name]
270
 
271
  model.eval()
@@ -298,19 +294,18 @@ example_list = [
298
  # example_list = [['/content/new_labels.csv',"ResNet50"]]
299
 
300
  gradio_app = gradio.Interface(
301
- fn = partial(run_diagnosis, preprocess_fn = preprocess_fxn, Idx2labels = labels_dict, threshold = configs["THRESHOLD"]),
302
 
303
- # inputs = [gradio.Dropdown(["ConvNeXt(small)", "ConvNeXt(tiny)", "EfficientNet(v2_small)", "EfficientNet(b3)", "RegNet(x3_2GF)","ResNet50"], value="EfficientNet(b3)", label="Select Backbone Model"),
304
- # gradio.Image(type="pil", label="Load chest-X-ray image here")],
305
  inputs = [gradio.Dropdown(["CheXFormer-small", "ViT-base-16"], value="ViT-base-16", label="Select Backbone Model"),
306
- gradio.Image(type="pil", label="Load chest-X-ray image here")],
 
307
 
308
- outputs = [gradio.Textbox(label="Predicted Medical Conditions"),
309
  gradio.Label(label="Predicted Probabilities", show_label=False)],
310
 
311
  examples = example_list,
312
  cache_examples = True,
313
- title = "ChestVision",
314
  description = "Vision-Transformer solutions for assistive medical diagnosis with Vision-Language-based prediction justification",
315
  article = "Author: C. Foli (02.2026) | Website: coming soon...")
316
 
 
7
  https://colab.research.google.com/drive/1gVrx5TyipNPvn8D7GaK0pNBCnLeYTAD_
8
  """
9
 
 
 
 
 
10
  """### Import dependencies"""
11
 
12
  import torch
 
252
  x = preprocess_fn(input_image).unsqueeze(0)
253
 
254
  # Resolve backbone
255
+ # backbone_info = MODEL_REGISTRY[backbone_name]
256
+ ckpt_path = os.path.join(CKPT_ROOT, MODEL_REGISTRY[backbone_name])
257
 
258
  if not os.path.exists(ckpt_path):
259
  raise FileNotFoundError(f"Checkpoint not found: {ckpt_path}")
 
261
  # Load model (cache for speed)
262
  if backbone_name not in MODEL_CACHE:
263
  MODEL_CACHE[backbone_name] = modelModule.load_from_checkpoint(
264
+ ckpt_path, backbone_model_name=MODEL_REGISTRY[backbone_name], num_layers_to_unfreeze = 2)
265
  model = MODEL_CACHE[backbone_name]
266
 
267
  model.eval()
 
294
  # example_list = [['/content/new_labels.csv',"ResNet50"]]
295
 
296
  gradio_app = gradio.Interface(
297
+ fn = partial(run_diagnosis, preprocess_fn = preprocess_fxn, Idx2labels = labels_dict),
298
 
 
 
299
  inputs = [gradio.Dropdown(["CheXFormer-small", "ViT-base-16"], value="ViT-base-16", label="Select Backbone Model"),
300
+ gradio.Image(type="pil", label="Load chest-X-ray image here"),
301
+ gradio.Slider(minimum = 0.1, maximum = 0.9, step = 0.05, value = 0.4, label = "Set Prediction Threshold")],
302
 
303
+ outputs = [gradio.Textbox(label="Predicted Medical Condition(s)"),
304
  gradio.Label(label="Predicted Probabilities", show_label=False)],
305
 
306
  examples = example_list,
307
  cache_examples = True,
308
+ title = "ChestVision-PRO",
309
  description = "Vision-Transformer solutions for assistive medical diagnosis with Vision-Language-based prediction justification",
310
  article = "Author: C. Foli (02.2026) | Website: coming soon...")
311