File size: 1,585 Bytes
63008be
ecbc519
 
63008be
 
ecbc519
63008be
ecbc519
 
63008be
ecbc519
 
63008be
 
005ae32
63008be
ecbc519
63008be
ecbc519
bdac973
 
 
 
 
63008be
9795cc8
63008be
3e2f980
bdac973
ecbc519
63008be
13c1f49
 
ecbc519
 
bdac973
 
ecbc519
63008be
9795cc8
7d27149
c2ac1f0
333c10b
2ef06e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()