File size: 1,994 Bytes
9f1a43f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Lung Detector

A Gradio web app that detects lung diseases from chest X-ray images using a CNN model.

## Run & Operate

- `PORT=8000 python3 app.py` β€” start the Gradio app (workflow: "Lung Detector")
- `pip install -r requirements.txt` β€” install Python dependencies

## Stack

- Python 3.11
- Gradio (UI)
- TensorFlow / Keras (CNN model inference)
- Pillow, NumPy (image preprocessing)
- `model_setup.py` β€” file path resolver (local + HuggingFace Hub)

## Where things live

- `app.py` β€” main Gradio application
- `model_setup.py` β€” maps filenames to local paths (or HF Hub downloads)
- `model_config.json` β€” HuggingFace Hub config (hub_repo_id, hub_files)
- `cnn_model_lung_detection.keras` β€” the trained CNN model
- `requirements.txt` β€” Python dependencies

## Architecture decisions

- Always load model files via `model_setup.paths["filename"]` β€” never hard-coded paths
- Model input: 128Γ—128 RGB, normalized to [0, 1]
- Model output: 4-class softmax (COVID-19, Normal, Viral Pneumonia, Lung Opacity)
- CSS + theme passed to `demo.launch()` (Gradio 6.0 API)
- Port read from `PORT` env var, defaulting to 7860

## Product

Users upload a chest X-ray image. The app runs CNN inference and displays:
- Primary finding label (COVID-19 / Normal / Viral Pneumonia / Lung Opacity)
- Confidence percentage
- Clinical description of the finding
- Probability bar chart for all 4 classes

## User preferences

- Pure Python project β€” no TypeScript, React, or database scaffolding
- Flat file tree (no lib/, no artifacts/ for the Python app)
- Medical tool visual style: dark background, thin letters, professional
- Always use `model_setup.paths["<filename>"]` for file loading

## Gotchas

- Port 8080 is used by the API server artifact; use 8000 for the Python app
- Gradio 6.0: pass `css` and `theme` to `launch()`, not `Blocks()`
- CUDA warnings at startup are expected (CPU inference only)
- `cnn_model_lung_detection.keras` β€” 4 output classes with softmax activation