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()