rizmyabdulla's picture
Rename main.py to app.py
19fa990
raw
history blame
1.3 kB
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.split(',') for s in data['Symptoms']]
X = mlb.fit_transform(symptoms)
disease = pd.get_dummies(data['Disease'])
disease_list = list(disease.columns)
# Define the prediction function
def predict_disease(symptoms):
# Preprocess the user input
user_symptoms = [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
return f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}"
# 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()