|
|
import gradio as gr |
|
|
import pickle |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
with open('disease_prediction_model.pkl', 'rb') as model_file: |
|
|
model = pickle.load(model_file) |
|
|
|
|
|
|
|
|
def predict_disease(age, gender, fever, cough, fatigue, difficulty_breathing, blood_pressure, cholesterol_level): |
|
|
|
|
|
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] |
|
|
|
|
|
|
|
|
input_features = np.array([[age, gender, fever, cough, fatigue, difficulty_breathing, blood_pressure, cholesterol_level]]) |
|
|
|
|
|
|
|
|
prediction = model.predict(input_features) |
|
|
return prediction[0] |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
app = gr.Interface(fn=predict_disease, inputs=inputs, outputs=outputs, title="Symptom to Disease Prediction") |
|
|
|
|
|
app.launch() |
|
|
|