Nos7 commited on
Commit
91c18a1
·
verified ·
1 Parent(s): 28d6da1

Upload demo.ipynb

Browse files
Files changed (1) hide show
  1. demo.ipynb +179 -0
demo.ipynb ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "ee8a97cd-18d9-451f-8859-52385b36bf90",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "# Import Dependencies\n",
11
+ "import gradio as gr\n",
12
+ "import pandas as pd\n",
13
+ "import numpy as np\n",
14
+ "from joblib import load"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 2,
20
+ "id": "a34c486f-d26f-46f1-83d0-8cbb7ea8b3a3",
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "# Function to make Inference\n",
25
+ "def predict_disease_from_symptom(symptom_list):\n",
26
+ " symptoms = {'itching': 0, 'skin_rash': 0, 'nodal_skin_eruptions': 0, 'continuous_sneezing': 0,\n",
27
+ " 'shivering': 0, 'chills': 0, 'joint_pain': 0, 'stomach_pain': 0, 'acidity': 0, 'ulcers_on_tongue': 0,\n",
28
+ " 'muscle_wasting': 0, 'vomiting': 0, 'burning_micturition': 0, 'spotting_ urination': 0, 'fatigue': 0,\n",
29
+ " 'weight_gain': 0, 'anxiety': 0, 'cold_hands_and_feets': 0, 'mood_swings': 0, 'weight_loss': 0,\n",
30
+ " 'restlessness': 0, 'lethargy': 0, 'patches_in_throat': 0, 'irregular_sugar_level': 0, 'cough': 0,\n",
31
+ " 'high_fever': 0, 'sunken_eyes': 0, 'breathlessness': 0, 'sweating': 0, 'dehydration': 0,\n",
32
+ " 'indigestion': 0, 'headache': 0, 'yellowish_skin': 0, 'dark_urine': 0, 'nausea': 0, 'loss_of_appetite': 0,\n",
33
+ " 'pain_behind_the_eyes': 0, 'back_pain': 0, 'constipation': 0, 'abdominal_pain': 0, 'diarrhoea': 0, 'mild_fever': 0,\n",
34
+ " 'yellow_urine': 0, 'yellowing_of_eyes': 0, 'acute_liver_failure': 0, 'fluid_overload': 0, 'swelling_of_stomach': 0,\n",
35
+ " 'swelled_lymph_nodes': 0, 'malaise': 0, 'blurred_and_distorted_vision': 0, 'phlegm': 0, 'throat_irritation': 0,\n",
36
+ " 'redness_of_eyes': 0, 'sinus_pressure': 0, 'runny_nose': 0, 'congestion': 0, 'chest_pain': 0, 'weakness_in_limbs': 0,\n",
37
+ " 'fast_heart_rate': 0, 'pain_during_bowel_movements': 0, 'pain_in_anal_region': 0, 'bloody_stool': 0,\n",
38
+ " 'irritation_in_anus': 0, 'neck_pain': 0, 'dizziness': 0, 'cramps': 0, 'bruising': 0, 'obesity': 0, 'swollen_legs': 0,\n",
39
+ " 'swollen_blood_vessels': 0, 'puffy_face_and_eyes': 0, 'enlarged_thyroid': 0, 'brittle_nails': 0, 'swollen_extremeties': 0,\n",
40
+ " 'excessive_hunger': 0, 'extra_marital_contacts': 0, 'drying_and_tingling_lips': 0, 'slurred_speech': 0,\n",
41
+ " 'knee_pain': 0, 'hip_joint_pain': 0, 'muscle_weakness': 0, 'stiff_neck': 0, 'swelling_joints': 0, 'movement_stiffness': 0,\n",
42
+ " 'spinning_movements': 0, 'loss_of_balance': 0, 'unsteadiness': 0, 'weakness_of_one_body_side': 0, 'loss_of_smell': 0,\n",
43
+ " 'bladder_discomfort': 0, 'foul_smell_of urine': 0, 'continuous_feel_of_urine': 0, 'passage_of_gases': 0, 'internal_itching': 0,\n",
44
+ " 'toxic_look_(typhos)': 0, 'depression': 0, 'irritability': 0, 'muscle_pain': 0, 'altered_sensorium': 0,\n",
45
+ " 'red_spots_over_body': 0, 'belly_pain': 0, 'abnormal_menstruation': 0, 'dischromic _patches': 0, 'watering_from_eyes': 0,\n",
46
+ " 'increased_appetite': 0, 'polyuria': 0, 'family_history': 0, 'mucoid_sputum': 0, 'rusty_sputum': 0, 'lack_of_concentration': 0,\n",
47
+ " 'visual_disturbances': 0, 'receiving_blood_transfusion': 0, 'receiving_unsterile_injections': 0, 'coma': 0,\n",
48
+ " 'stomach_bleeding': 0, 'distention_of_abdomen': 0, 'history_of_alcohol_consumption': 0, 'fluid_overload.1': 0,\n",
49
+ " 'blood_in_sputum': 0, 'prominent_veins_on_calf': 0, 'palpitations': 0, 'painful_walking': 0, 'pus_filled_pimples': 0,\n",
50
+ " 'blackheads': 0, 'scurring': 0, 'skin_peeling': 0, 'silver_like_dusting': 0, 'small_dents_in_nails': 0, 'inflammatory_nails': 0,\n",
51
+ " 'blister': 0, 'red_sore_around_nose': 0, 'yellow_crust_ooze': 0}\n",
52
+ " \n",
53
+ " # Set value to 1 for corresponding symptoms\n",
54
+ " for s in symptom_list:\n",
55
+ " symptoms[s] = 1\n",
56
+ " \n",
57
+ " # Put all data in a test dataset\n",
58
+ " df_test = pd.DataFrame(columns=list(symptoms.keys()))\n",
59
+ " df_test.loc[0] = np.array(list(symptoms.values()))\n",
60
+ " \n",
61
+ " # Load pre-trained model\n",
62
+ " clf = load(str(\"./saved_model/random_forest.joblib\"))\n",
63
+ " result = clf.predict(df_test)\n",
64
+ " \n",
65
+ " # Cleanup\n",
66
+ " del df_test\n",
67
+ " \n",
68
+ " return f\"{result[0]}\""
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": 3,
74
+ "id": "b3f6901f-093a-4047-a552-36a09ae5a8df",
75
+ "metadata": {},
76
+ "outputs": [
77
+ {
78
+ "name": "stdout",
79
+ "output_type": "stream",
80
+ "text": [
81
+ "Running on local URL: http://127.0.0.1:7860/\n",
82
+ "Running on public URL: https://30475.gradio.app\n",
83
+ "\n",
84
+ "This share link will expire in 72 hours. To get longer links, send an email to: [email protected]\n"
85
+ ]
86
+ },
87
+ {
88
+ "data": {
89
+ "text/html": [
90
+ "\n",
91
+ " <iframe\n",
92
+ " width=\"900\"\n",
93
+ " height=\"500\"\n",
94
+ " src=\"https://30475.gradio.app\"\n",
95
+ " frameborder=\"0\"\n",
96
+ " allowfullscreen\n",
97
+ " \n",
98
+ " ></iframe>\n",
99
+ " "
100
+ ],
101
+ "text/plain": [
102
+ "<IPython.lib.display.IFrame at 0x208708d5490>"
103
+ ]
104
+ },
105
+ "metadata": {},
106
+ "output_type": "display_data"
107
+ },
108
+ {
109
+ "data": {
110
+ "text/plain": [
111
+ "(<Flask 'gradio.networking'>,\n",
112
+ " 'http://127.0.0.1:7860/',\n",
113
+ " 'https://30475.gradio.app')"
114
+ ]
115
+ },
116
+ "execution_count": 3,
117
+ "metadata": {},
118
+ "output_type": "execute_result"
119
+ }
120
+ ],
121
+ "source": [
122
+ "# Run Inference Server\n",
123
+ "# Click on Public URL to run demo on separate page or for sharing purposes\n",
124
+ "iface = gr.Interface(\n",
125
+ " predict_disease_from_symptom,\n",
126
+ " [\n",
127
+ " gr.inputs.CheckboxGroup(['itching', 'skin_rash', 'nodal_skin_eruptions', 'continuous_sneezing', 'shivering', 'chills', 'joint_pain', 'stomach_pain', 'acidity', 'ulcers_on_tongue',\n",
128
+ " 'muscle_wasting', 'vomiting', 'burning_micturition', 'spotting_ urination', 'fatigue', 'weight_gain', 'anxiety', 'cold_hands_and_feets', 'mood_swings', 'weight_loss',\n",
129
+ " 'restlessness', 'lethargy', 'patches_in_throat', 'irregular_sugar_level', 'cough', 'high_fever', 'sunken_eyes', 'breathlessness', 'sweating', 'dehydration',\n",
130
+ " 'indigestion', 'headache', 'yellowish_skin', 'dark_urine', 'nausea', 'loss_of_appetite', 'pain_behind_the_eyes', 'back_pain', 'constipation', 'abdominal_pain', 'diarrhoea', 'mild_fever',\n",
131
+ " 'yellow_urine', 'yellowing_of_eyes', 'acute_liver_failure', 'fluid_overload', 'swelling_of_stomach', 'swelled_lymph_nodes', 'malaise', 'blurred_and_distorted_vision', 'phlegm', 'throat_irritation',\n",
132
+ " 'redness_of_eyes', 'sinus_pressure', 'runny_nose', 'congestion', 'chest_pain', 'weakness_in_limbs', 'fast_heart_rate', 'pain_during_bowel_movements', 'pain_in_anal_region', 'bloody_stool',\n",
133
+ " 'irritation_in_anus', 'neck_pain', 'dizziness', 'cramps', 'bruising', 'obesity', 'swollen_legs', 'swollen_blood_vessels', 'puffy_face_and_eyes', 'enlarged_thyroid', 'brittle_nails', 'swollen_extremeties',\n",
134
+ " 'excessive_hunger', 'extra_marital_contacts', 'drying_and_tingling_lips', 'slurred_speech', 'knee_pain', 'hip_joint_pain', 'muscle_weakness', 'stiff_neck', 'swelling_joints', 'movement_stiffness',\n",
135
+ " 'spinning_movements', 'loss_of_balance', 'unsteadiness', 'weakness_of_one_body_side', 'loss_of_smell', 'bladder_discomfort', 'foul_smell_of urine', 'continuous_feel_of_urine', 'passage_of_gases', 'internal_itching',\n",
136
+ " 'toxic_look_(typhos)', 'depression', 'irritability', 'muscle_pain', 'altered_sensorium', 'red_spots_over_body', 'belly_pain', 'abnormal_menstruation', 'dischromic _patches', 'watering_from_eyes',\n",
137
+ " 'increased_appetite', 'polyuria', 'family_history', 'mucoid_sputum', 'rusty_sputum', 'lack_of_concentration', 'visual_disturbances', 'receiving_blood_transfusion', 'receiving_unsterile_injections', 'coma',\n",
138
+ " 'stomach_bleeding', 'distention_of_abdomen', 'history_of_alcohol_consumption', 'fluid_overload.1', 'blood_in_sputum', 'prominent_veins_on_calf', 'palpitations', 'painful_walking', 'pus_filled_pimples',\n",
139
+ " 'blackheads', 'scurring', 'skin_peeling', 'silver_like_dusting', 'small_dents_in_nails', 'inflammatory_nails', 'blister', 'red_sore_around_nose', 'yellow_crust_ooze']),\n",
140
+ " ],\n",
141
+ " \"text\",\n",
142
+ " description=\"Select a symptom from the list and click submit to get predicted Disease as the Output. \\\n",
143
+ " [ NOTE: This app is meant for demo purposes only. Please consult a Doctor if you have any symptoms. ]\"\n",
144
+ ")\n",
145
+ "\n",
146
+ "iface.launch(share=True)"
147
+ ]
148
+ },
149
+ {
150
+ "cell_type": "code",
151
+ "execution_count": null,
152
+ "id": "2e2c4220-6660-4ad7-9cce-244f53971ba6",
153
+ "metadata": {},
154
+ "outputs": [],
155
+ "source": []
156
+ }
157
+ ],
158
+ "metadata": {
159
+ "kernelspec": {
160
+ "display_name": "Python 3 (ipykernel)",
161
+ "language": "python",
162
+ "name": "python3"
163
+ },
164
+ "language_info": {
165
+ "codemirror_mode": {
166
+ "name": "ipython",
167
+ "version": 3
168
+ },
169
+ "file_extension": ".py",
170
+ "mimetype": "text/x-python",
171
+ "name": "python",
172
+ "nbconvert_exporter": "python",
173
+ "pygments_lexer": "ipython3",
174
+ "version": "3.8.5"
175
+ }
176
+ },
177
+ "nbformat": 4,
178
+ "nbformat_minor": 5
179
+ }