File size: 914 Bytes
7a59dab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from utils import load_model, predict_image

# Load model once
model = load_model("model/best_classification_model.pth", num_classes=3)
class_names = ['COVID', 'Normal', 'Viral Pneumonia']

def classify_xray(img):
    prediction = predict_image(img, model, class_names)
    return f"🧠 Predicted: {prediction}"

# Gradio UI
title = "🩻 COVID-19 Chest X-ray Classifier"
description = """
Upload a Chest X-ray image and let the AI classify it as:
- **COVID**
- **Normal**
- **Viral Pneumonia**
<br><br>
🧠 Powered by ResNet18 + PyTorch
"""

demo = gr.Interface(
    fn=classify_xray,
    inputs=gr.Image(type="filepath", label="Upload Chest X-ray"),
    outputs=gr.Textbox(label="Prediction"),
    title=title,
    description=description,
    examples=["examples/x-ray.jpg"],
    theme="soft",  # use "huggingface" or "default" if preferred
)

if __name__ == "__main__":
    demo.launch()