File size: 1,958 Bytes
ec24255
 
 
 
 
97407b6
ec24255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9dec907
ec24255
9dec907
 
 
 
 
 
 
 
ec24255
 
9dec907
ec24255
 
 
 
 
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
import gradio as gr
import pickle
import numpy as np

# Load your model from the .pkl file
with open('disease_prediction_model.pkl', 'rb') as model_file:
    model = pickle.load(model_file)

# Define the prediction function
def predict_disease(age, gender, fever, cough, fatigue, difficulty_breathing, blood_pressure, cholesterol_level):
    # Convert inputs to numerical or categorical as your model expects
    gender = 0 if gender == "Male" else 1
    fever = 1 if fever == "Yes" else 0
    cough = 1 if cough == "Yes" else 0
    fatigue = 1 if fatigue == "Yes" else 0
    difficulty_breathing = 1 if difficulty_breathing == "Yes" else 0
    blood_pressure_mapping = {"Low": 0, "Normal": 1, "High": 2}
    cholesterol_level_mapping = {"Low": 0, "Normal": 1, "High": 2}
    
    blood_pressure = blood_pressure_mapping[blood_pressure]
    cholesterol_level = cholesterol_level_mapping[cholesterol_level]

    # Assuming your model takes input as a NumPy array or similar format
    input_features = np.array([[age, gender, fever, cough, fatigue, difficulty_breathing, blood_pressure, cholesterol_level]])

    # Get the prediction
    prediction = model.predict(input_features)
    return prediction[0]  # Return the predicted disease

# Gradio interface using new components
inputs = [
    gr.Number(label="Age"),
    gr.Radio(choices=["Male", "Female"], label="Gender"),
    gr.Radio(choices=["Yes", "No"], label="Fever"),
    gr.Radio(choices=["Yes", "No"], label="Cough"),
    gr.Radio(choices=["Yes", "No"], label="Fatigue"),
    gr.Radio(choices=["Yes", "No"], label="Difficulty Breathing"),
    gr.Dropdown(choices=["Low", "Normal", "High"], label="Blood Pressure"),
    gr.Dropdown(choices=["Low", "Normal", "High"], label="Cholesterol Level")
]

outputs = gr.Textbox(label="Predicted Disease")

# Create and launch the app
app = gr.Interface(fn=predict_disease, inputs=inputs, outputs=outputs, title="Symptom to Disease Prediction")

app.launch()