File size: 3,391 Bytes
f054618
 
 
 
 
a44e524
f054618
 
a44e524
 
 
 
 
 
 
f054618
 
 
 
a44e524
f054618
a44e524
 
 
 
 
 
f054618
a44e524
f054618
 
 
 
 
 
 
a44e524
 
 
 
 
 
 
 
f054618
 
 
a44e524
f054618
a44e524
f054618
 
 
 
 
 
a44e524
f054618
 
 
 
 
 
a44e524
f054618
 
a44e524
f054618
 
a44e524
f054618
 
 
 
 
 
 
a44e524
f054618
 
 
 
 
 
 
 
 
 
 
 
a44e524
f054618
 
 
 
 
 
a44e524
 
f054618
 
a44e524
f054618
 
 
a44e524
f054618
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import gradio as gr
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image

# Load model
model = load_model('xray_image_classifier_model.keras')

# Define solutions
solutions = {
    "Pneumonia": "Consult a doctor immediately. Follow prescribed antibiotics if given, rest well, and stay hydrated.",
    "Normal": "Your X-ray appears normal. However, if you experience symptoms, consult a doctor for further evaluation."
}

# Prediction function
def predict(image):
    img = image.resize((150, 150))
    img_array = np.array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)
    
    prediction = model.predict(img_array)
    predicted_class = "Pneumonia" if prediction > 0.5 else "Normal"
    
    # Get the corresponding solution
    solution = solutions.get(predicted_class, "No specific advice available.")
    
    return predicted_class, solution

# CSS Styling
css = """
    .gradio-container {
        background-color: #f5f5f5;
        font-family: Arial, sans-serif;
    }
    
    .gr-button {
        background-color:#007bff;
        color: white; 
        border: none;
        border-radius: 5px;
        font-size: 16px;
        padding: 10px 20px;
        cursor: pointer;
        transition: background-color 0.3s ease;
    }

    .gr-button:hover {
        background-color: #0056b3;
    }

    .gr-textbox, .gr-image {
        border: 2px dashed #007bff;
        padding: 20px;
        border-radius: 10px;
        background-color: #ffffff;
    }

    .gr-box-text {
        color: #007bff;
        font-size: 22px;
        font-weight: bold;
        text-align: center;
    }

    h1 {
        font-size: 36px;
        color: #007bff;
        text-align: center;
    }

    p {
        font-size: 20px;
        color: #333;
        text-align: center;
    }
"""

# Description
description = """
**Automated Pneumonia Detection via Chest X-ray Classification**

This model leverages deep learning techniques to classify chest X-ray images as either 'Pneumonia' or 'Normal.' By utilizing the InceptionV3 architecture for transfer learning, combined with data preprocessing and augmentation, the model aims to deliver powerful performance in medical image analysis. It enhances the automation of diagnostic processes, aiding in the detection of pneumonia with high accuracy.

**Technologies Employed:**
- TensorFlow & Keras for model development
- InceptionV3 for transfer learning
- Numpy, Pandas, and Matplotlib for data handling and visualization
- Flask and Gradio for deployment and user interaction
"""

# Gradio UI
with gr.Blocks(css=css) as interface:
    gr.Markdown("<h1>Automated Pneumonia Detection via Chest X-ray Classification</h1>")
    gr.Markdown("<p>Submit a chest X-ray image below.</p>")
    
    with gr.Row():
        image_input = gr.Image(label="Drop Image Here", type="pil", elem_classes=["gr-image", "gr-box-text"])
        output_prediction = gr.Textbox(label="Model Analysis Output", elem_classes=["gr-textbox", "gr-box-text"])
        output_solution = gr.Textbox(label="Recommended Solution", elem_classes=["gr-textbox", "gr-box-text"])

    submit_btn = gr.Button("Initiate Diagnostic Analysis", elem_classes=["gr-button"])
    submit_btn.click(fn=predict, inputs=image_input, outputs=[output_prediction, output_solution])
    
    gr.Markdown(description)

# Launch the app
interface.launch()