|
import gradio as gr |
|
import pandas as pd |
|
import numpy as np |
|
from sklearn.preprocessing import MultiLabelBinarizer |
|
from keras.models import load_model |
|
|
|
|
|
model = load_model('model.h5') |
|
|
|
|
|
data = pd.read_csv('dataset.csv') |
|
|
|
|
|
mlb = MultiLabelBinarizer() |
|
symptoms = [s.lower().split(',') for s in data['Symptoms']] |
|
X = mlb.fit_transform(symptoms) |
|
disease = pd.get_dummies(data['Disease']) |
|
disease_list = list(disease.columns) |
|
|
|
|
|
X_test = np.expand_dims(X, axis=2) |
|
Y_test = disease.values |
|
loss, accuracy = model.evaluate(X_test, Y_test, verbose=0) |
|
|
|
|
|
def predict_disease(symptoms): |
|
|
|
user_symptoms = [symptom.strip().replace(' ', '_').lower() for symptom in symptoms.split(',')] |
|
user_X = mlb.transform([user_symptoms]) |
|
|
|
|
|
prediction = model.predict(np.expand_dims(user_X, axis=2)) |
|
predicted_disease = disease_list[np.argmax(prediction)] |
|
predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0] |
|
|
|
|
|
return f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}\n\nModel accuracy on testing set: {accuracy:.3f}" |
|
|
|
|
|
inputs = gr.inputs.Textbox(label="Symptoms") |
|
outputs = gr.outputs.Textbox(label="Prediction") |
|
gradio_interface = gr.Interface(predict_disease, inputs, outputs, title="Disease Prediction App") |
|
|
|
gradio_interface.launch() |
|
|