Spaces:
Runtime error
Runtime error
Upload 4 files
Browse filesAdded random forest model
- RandomForest.pkl +3 -0
- app.py +82 -0
- label_encoder.pkl +3 -0
- requirements.txt +5 -0
RandomForest.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:722c30a61d0092d6a989fe92fca6f2fd8b5939d8a015b4464372521e4f2126e5
|
3 |
+
size 2742994
|
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import pickle
|
3 |
+
import pandas as pd
|
4 |
+
from collections import Counter
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
|
8 |
+
# Load the trained models
|
9 |
+
with open('RandomForest.pkl', 'rb') as rf_file:
|
10 |
+
random_forest_model = pickle.load(rf_file)
|
11 |
+
|
12 |
+
# with open('knn_model.pkl', 'rb') as knn_file:
|
13 |
+
# knn_model = pickle.load(knn_file)
|
14 |
+
#
|
15 |
+
# with open('mlp_model.pkl', 'rb') as mlp_file:
|
16 |
+
# mlp_model = pickle.load(mlp_file)
|
17 |
+
#
|
18 |
+
# with open('xgboost_model.pkl', 'rb') as xgb_file:
|
19 |
+
# xgboost_model = pickle.load(xgb_file)
|
20 |
+
|
21 |
+
# Load the LabelEncoder
|
22 |
+
with open('label_encoder.pkl', 'rb') as le_file:
|
23 |
+
label_encoder = pickle.load(le_file)
|
24 |
+
|
25 |
+
symptom_columns = ['itching', 'shivering', 'chills', 'acidity', 'vomiting', 'fatigue', 'anxiety', 'restlessness', 'lethargy', 'cough', 'breathlessness', 'sweating', 'dehydration', 'indigestion', 'headache', 'nausea', 'constipation', 'diarrhoea', 'malaise', 'phlegm', 'congestion', 'dizziness', 'cramps', 'bruising', 'obesity', 'unsteadiness', 'depression', 'irritability', 'polyuria', 'coma', 'palpitations', 'blackheads', 'scurring', 'blister', 'skin rash', 'pus filled pimples', 'mood swings', 'weight loss', 'fast heart rate', 'excessive hunger', 'muscle weakness', 'abnormal menstruation', 'muscle wasting', 'patches in throat', 'high fever', 'extra marital contacts', 'yellowish skin', 'loss of appetite', 'abdominal pain', 'yellowing of eyes', 'chest pain', 'loss of balance', 'lack of concentration', 'blurred and distorted vision', 'drying and tingling lips', 'slurred speech', 'stiff neck', 'swelling joints', 'painful walking', 'dark urine', 'yellow urine', 'receiving blood transfusion', 'receiving unsterile injections', 'visual disturbances', 'burning micturition', 'bladder discomfort', 'foul smell of urine', 'continuous feel of urine', 'irregular sugar level', 'increased appetite', 'joint pain', 'skin peeling', 'small dents in nails', 'inflammatory nails', 'swelling of stomach', 'distention of abdomen', 'history of alcohol consumption', 'fluid overload', 'pain during bowel movements', 'pain in anal region', 'bloody stool', 'irritation in anus', 'acute liver failure', 'stomach bleeding', 'back pain', 'weakness in limbs', 'neck pain', 'mucoid sputum', 'mild fever', 'muscle pain', 'family history', 'continuous sneezing', 'watering from eyes', 'rusty sputum', 'weight gain', 'puffy face and eyes', 'enlarged thyroid', 'brittle nails', 'swollen extremeties', 'swollen legs', 'prominent veins on calf', 'stomach pain', 'spinning movements', 'sunken eyes', 'silver like dusting', 'swelled lymph nodes', 'blood in sputum', 'swollen blood vessels', 'toxic look (typhos)', 'belly pain', 'throat irritation', 'redness of eyes', 'sinus pressure', 'runny nose', 'loss of smell', 'passage of gases', 'cold hands and feets', 'weakness of one body side', 'altered sensorium', 'nodal skin eruptions', 'red sore around nose', 'yellow crust ooze', 'ulcers on tongue', 'spotting urination', 'pain behind the eyes', 'red spots over body', 'internal itching', 'movement stiffness', 'knee pain', 'hip joint pain', 'dischromic patches']
|
26 |
+
|
27 |
+
@app.route('/predict', methods=['POST'])
|
28 |
+
def predict():
|
29 |
+
try:
|
30 |
+
# Parse user input from JSON
|
31 |
+
# user_input = request.json
|
32 |
+
user_input = {
|
33 |
+
'itching': 1,
|
34 |
+
'skin_rash': 1,
|
35 |
+
'nodal_skin_eruptions': 0,
|
36 |
+
'continuous_sneezing': 1,
|
37 |
+
'shivering': 1,
|
38 |
+
'chills': 1,
|
39 |
+
'joint_pain': 1,
|
40 |
+
'stomach_pain': 1,
|
41 |
+
}
|
42 |
+
# Preprocess input data
|
43 |
+
user_df = pd.DataFrame([user_input], columns=symptom_columns).fillna(0)
|
44 |
+
input_data = user_df.values
|
45 |
+
|
46 |
+
# Get predictions from all models
|
47 |
+
rf_pred = random_forest_model.predict(input_data)[0]
|
48 |
+
# knn_pred = knn_model.predict(input_data)[0]
|
49 |
+
# mlp_pred = mlp_model.predict(input_data)[0]
|
50 |
+
# xgb_pred = xgboost_model.predict(input_data)[0]
|
51 |
+
|
52 |
+
# Decode predictions into disease names
|
53 |
+
rf_label = label_encoder.inverse_transform([rf_pred])[0]
|
54 |
+
# knn_label = label_encoder.inverse_transform([knn_pred])[0]
|
55 |
+
# mlp_label = label_encoder.inverse_transform([mlp_pred])[0]
|
56 |
+
# xgb_label = label_encoder.inverse_transform([xgb_pred])[0]
|
57 |
+
|
58 |
+
# predictions = [rf_label, knn_label, mlp_label, xgb_label]
|
59 |
+
predictions = [rf_label]
|
60 |
+
print(predictions)
|
61 |
+
majority_label = Counter(predictions).most_common(1)[0][0]
|
62 |
+
|
63 |
+
# return jsonify({
|
64 |
+
# 'predictions': {
|
65 |
+
# 'Random Forest': rf_label,
|
66 |
+
# 'KNN': knn_label,
|
67 |
+
# 'MLP': mlp_label,
|
68 |
+
# 'XGBoost': xgb_label
|
69 |
+
# },
|
70 |
+
# 'majority_prediction': majority_label
|
71 |
+
# })
|
72 |
+
return jsonify({
|
73 |
+
'predictions': {
|
74 |
+
'Random Forest': rf_label,
|
75 |
+
},
|
76 |
+
'majority_prediction': majority_label
|
77 |
+
})
|
78 |
+
except Exception as e:
|
79 |
+
return jsonify({'error': str(e)}), 400
|
80 |
+
|
81 |
+
if __name__ == '__main__':
|
82 |
+
app.run(debug=True)
|
label_encoder.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5729ce2e45a61c0942d49ac5a4dada1f71855dfcf15f31e51f8bc034028ce8b4
|
3 |
+
size 901
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
flask
|
2 |
+
pandas
|
3 |
+
scikit-learn
|
4 |
+
xgboost
|
5 |
+
torch
|