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",description="Symptoms used for this project : itching, skin_rash, nodal_skin_eruptions, dischromic _patches, skin_rash, continuous_sneezing, shivering, chills, watering_from_eyes, shivering, stomach_pain, acidity, ulcers_on_tongue, vomiting, cough, chest_pain, acidity, yellowish_skin, nausea, loss_of_appetite, abdominal_pain, yellowing_of_eyes, vomiting, stomach_pain, burning_micturition, spotting_ urination, passage_of_gases, internal_itching, indigestion, indigestion, muscle_wasting, patches_in_throat, high_fever, extra_marital_contacts, patches_in_throat, fatigue, weight_loss, restlessness, lethargy, irregular_sugar_level, blurred_and_distorted_vision, obesity, excessive_hunger, increased_appetite, polyuria, weight_loss, sunken_eyes, dehydration, diarrhoea, sunken_eyes, breathlessness, family_history, mucoid_sputum, cough, headache, dizziness, loss_of_balance, lack_of_concentration, chest_pain, headache, stiff_neck, depression, irritability, visual_disturbances, back_pain, weakness_in_limbs, neck_pain, weakness_in_limbs, weakness_of_one_body_side, altered_sensorium, fatigue, dark_urine, chills, sweating, muscle_pain, mild_fever, swelled_lymph_nodes, malaise, red_spots_over_body, joint_pain, pain_behind_the_eyes, back_pain, constipation, toxic_look_(typhos), belly_pain, joint_pain, yellow_urine, receiving_blood_transfusion, receiving_unsterile_injections, yellowish_skin, coma, stomach_bleeding, acute_liver_failure, swelling_of_stomach, distention_of_abdomen, history_of_alcohol_consumption, fluid_overload, phlegm, blood_in_sputum, throat_irritation, redness_of_eyes, sinus_pressure, runny_nose, congestion, loss_of_smell, fast_heart_rate, rusty_sputum, constipation, pain_during_bowel_movements, pain_in_anal_region, bloody_stool, irritation_in_anus, pain_during_bowel_movements, breathlessness, cramps, bruising, swollen_legs, swollen_blood_vessels, prominent_veins_on_calf, cramps, weight_gain, cold_hands_and_feets, mood_swings, puffy_face_and_eyes, enlarged_thyroid, brittle_nails, swollen_extremeties, abnormal_menstruation, weight_gain, muscle_weakness, mood_swings, anxiety, slurred_speech, palpitations, drying_and_tingling_lips, knee_pain, hip_joint_pain, swelling_joints, painful_walking, neck_pain, muscle_weakness, movement_stiffness, stiff_neck, spinning_movements, unsteadiness, pus_filled_pimples, blackheads, scurring, pus_filled_pimples, burning_micturition, bladder_discomfort, foul_smell_of urine, continuous_feel_of_urine, bladder_discomfort, skin_peeling, silver_like_dusting, small_dents_in_nails, inflammatory_nails, blister, red_sore_around_nose, yellow_crust_ooze, high_fever, vomiting, skin_rash, itching, chills, Symptoms, continuous_sneezing, chills, sweating, loss_of_appetite, mild_fever, yellowing_of_eyes, swelled_lymph_nodes, malaise, phlegm, blood_in_sputum, throat_irritation, redness_of_eyes, sinus_pressure, runny_nose, congestion, loss_of_smell, muscle_pain, fast_heart_rate, rusty_sputum, fatigue, constipation, pain_in_anal_region, bloody_stool, irritation_in_anus, pain_during_bowel_movements, breathlessness, bruising, obesity, swollen_legs, swollen_blood_vessels, prominent_veins_on_calf, cramps, cold_hands_and_feets, lethargy, dizziness, puffy_face_and_eyes, enlarged_thyroid, brittle_nails, swollen_extremeties, depression, irritability, abnormal_menstruation, weight_gain, restlessness, diarrhoea, excessive_hunger, mood_swings, anxiety, nausea, blurred_and_distorted_vision, slurred_speech, palpitations, drying_and_tingling_lips, joint_pain, knee_pain, hip_joint_pain, swelling_joints, painful_walking, neck_pain, muscle_weakness, movement_stiffness, stiff_neck, spinning_movements, loss_of_balance, unsteadiness, headache, blackheads, scurring, pus_filled_pimples, burning_micturition, foul_smell_of urine, continuous_feel_of_urine, bladder_discomfort, skin_peeling, silver_like_dusting, small_dents_in_nails, inflammatory_nails, blister, red_sore_around_nose, yellow_crust_ooze, high_fever, nodal_skin_eruptions, dischromic _patches, watering_from_eyes, shivering, stomach_pain, ulcers_on_tongue, acidity, abdominal_pain, spotting_ urination, passage_of_gases, internal_itching, indigestion, muscle_wasting, extra_marital_contacts, patches_in_throat, irregular_sugar_level, increased_appetite, polyuria, weight_loss, dehydration, sunken_eyes, family_history, mucoid_sputum, cough, lack_of_concentration, chest_pain, visual_disturbances, back_pain, weakness_in_limbs, weakness_of_one_body_side, altered_sensorium, dark_urine, red_spots_over_body, pain_behind_the_eyes, toxic_look_(typhos), belly_pain, yellow_urine, receiving_blood_transfusion, receiving_unsterile_injections, yellowish_skin, coma, stomach_bleeding, acute_liver_failure, swelling_of_stomach, distention_of_abdomen, history_of_alcohol_consumption, fluid_overload, vomiting, joint_pain") | |
| # Launch the Gradio interface | |
| gradio_interface.launch() | |