Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load your model from the .pkl file
|
| 6 |
+
with open('model.pkl', 'rb') as model_file:
|
| 7 |
+
model = pickle.load(model_file)
|
| 8 |
+
|
| 9 |
+
# Define the prediction function
|
| 10 |
+
def predict_disease(age, gender, fever, cough, fatigue, difficulty_breathing, blood_pressure, cholesterol_level):
|
| 11 |
+
# Convert inputs to numerical or categorical as your model expects
|
| 12 |
+
gender = 0 if gender == "Male" else 1
|
| 13 |
+
fever = 1 if fever == "Yes" else 0
|
| 14 |
+
cough = 1 if cough == "Yes" else 0
|
| 15 |
+
fatigue = 1 if fatigue == "Yes" else 0
|
| 16 |
+
difficulty_breathing = 1 if difficulty_breathing == "Yes" else 0
|
| 17 |
+
blood_pressure_mapping = {"Low": 0, "Normal": 1, "High": 2}
|
| 18 |
+
cholesterol_level_mapping = {"Low": 0, "Normal": 1, "High": 2}
|
| 19 |
+
|
| 20 |
+
blood_pressure = blood_pressure_mapping[blood_pressure]
|
| 21 |
+
cholesterol_level = cholesterol_level_mapping[cholesterol_level]
|
| 22 |
+
|
| 23 |
+
# Assuming your model takes input as a NumPy array or similar format
|
| 24 |
+
input_features = np.array([[age, gender, fever, cough, fatigue, difficulty_breathing, blood_pressure, cholesterol_level]])
|
| 25 |
+
|
| 26 |
+
# Get the prediction
|
| 27 |
+
prediction = model.predict(input_features)
|
| 28 |
+
return prediction[0] # Return the predicted disease
|
| 29 |
+
|
| 30 |
+
# Gradio interface
|
| 31 |
+
inputs = [
|
| 32 |
+
gr.inputs.Number(label="Age"),
|
| 33 |
+
gr.inputs.Radio(choices=["Male", "Female"], label="Gender"),
|
| 34 |
+
gr.inputs.Radio(choices=["Yes", "No"], label="Fever"),
|
| 35 |
+
gr.inputs.Radio(choices=["Yes", "No"], label="Cough"),
|
| 36 |
+
gr.inputs.Radio(choices=["Yes", "No"], label="Fatigue"),
|
| 37 |
+
gr.inputs.Radio(choices=["Yes", "No"], label="Difficulty Breathing"),
|
| 38 |
+
gr.inputs.Dropdown(choices=["Low", "Normal", "High"], label="Blood Pressure"),
|
| 39 |
+
gr.inputs.Dropdown(choices=["Low", "Normal", "High"], label="Cholesterol Level")
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
outputs = gr.outputs.Textbox(label="Predicted Disease")
|
| 43 |
+
|
| 44 |
+
# Create and launch the app
|
| 45 |
+
app = gr.Interface(fn=predict_disease, inputs=inputs, outputs=outputs, title="Symptom to Disease Prediction")
|
| 46 |
+
|
| 47 |
+
app.launch()
|