File size: 1,762 Bytes
d1115d3
 
dadd236
 
1929032
dadd236
8857c5c
d1115d3
1929032
 
 
d1115d3
dadd236
 
 
 
 
d1115d3
 
dadd236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import numpy as np
from tensorflow.keras.models import load_model
import pickle
from PIL import Image

# Load models
diabetes_model = pickle.load(open("modelv4.pkl", "rb"))
pneumonia_model = load_model("cnn_model (1).h5")
breast_cancer_model = pickle.load(open("model.pkl", "rb"))

def predict_diabetes(file):
    df = pd.read_csv(file)
    prediction = diabetes_model.predict(df)
    result = ["Positive" if p > 0.5 else "Negative" for p in prediction]
    return result

def predict_pneumonia(image):
    img = Image.open(image).convert('RGB')
    img = img.resize((150, 150))
    img = np.array(img) / 255.0
    img = img.reshape(1, 150, 150, 3)
    prediction = pneumonia_model.predict(img)[0][0]
    return "Positive" if prediction > 0.5 else "Negative"

def predict_breast_cancer(file):
    df = pd.read_csv(file)
    prediction = breast_cancer_model.predict(df)
    result = ["Positive" if p > 0.5 else "Negative" for p in prediction]
    return result

# Gradio Interface
diabetes_interface = gr.Interface(
    fn=predict_diabetes,
    inputs=gr.File(label="Upload CSV File for Diabetes"),
    outputs=gr.Label(label="Diabetes Prediction"),
)

pneumonia_interface = gr.Interface(
    fn=predict_pneumonia,
    inputs=gr.Image(type="file", label="Upload Chest X-ray Image"),
    outputs=gr.Label(label="Pneumonia Prediction"),
)

breast_cancer_interface = gr.Interface(
    fn=predict_breast_cancer,
    inputs=gr.File(label="Upload CSV File for Breast Cancer"),
    outputs=gr.Label(label="Breast Cancer Prediction"),
)

app = gr.TabbedInterface(
    [diabetes_interface, pneumonia_interface, breast_cancer_interface],
    ["Diabetes", "Pneumonia", "Breast Cancer"],
)

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