Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| from sklearn.preprocessing import MultiLabelBinarizer | |
| from keras.models import load_model | |
| # Load the trained model | |
| model = load_model('model.h5') | |
| # Load the dataset | |
| data = pd.read_csv('dataset.csv') | |
| # Preprocess the dataset | |
| 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) | |
| # Evaluate the model on the testing set | |
| X_test = np.expand_dims(X, axis=2) | |
| Y_test = disease.values | |
| loss, accuracy = model.evaluate(X_test, Y_test, verbose=0) | |
| # Define the prediction function | |
| def predict_disease(symptoms): | |
| # Preprocess the user input | |
| user_symptoms = [symptom.strip().replace(' ', '_').lower() for symptom in symptoms.split(',')] | |
| user_X = mlb.transform([user_symptoms]) | |
| # Make the prediction | |
| 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 the prediction and accuracy | |
| return f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}\n\nModel accuracy on testing set: {accuracy:.3f}" | |
| # Define the Gradio interface | |
| inputs = gr.inputs.Textbox(label="Symptoms") | |
| outputs = gr.outputs.Textbox(label="Prediction") | |
| gradio_interface = gr.Interface(predict_disease, inputs, outputs, title="Disease Prediction App") | |
| # Launch the Gradio interface | |
| gradio_interface.launch() | |