Spaces:
Sleeping
Sleeping
File size: 1,078 Bytes
ecbc519 |
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 46 47 |
from flask import Flask, request, jsonify
from keras.models import load_model
import pandas as pd
import numpy as np
import pickle
app = Flask(__name__)
# load the model
model = load_model('model.h5')
# load the dataset
data = pd.read_csv('dataset.csv')
disease = pd.get_dummies(data['Disease'])
with open('mlb.pkl', 'rb') as f:
mlb = pickle.load(f)
@app.route('/predict', methods=['POST'])
def predict():
symptoms_to_predict = request.json['symptoms']
symptoms_array = mlb.transform([symptoms_to_predict])
disease_prediction = model.predict(np.expand_dims(symptoms_array, axis=2))
predicted_disease_index = np.argmax(disease_prediction)
predicted_disease = disease.columns[predicted_disease_index]
predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0]
output = {
'disease': predicted_disease,
'antibiotics': predicted_antibiotics
}
# return the output as JSON
response = jsonify(output)
return response
if __name__ == '__main__':
app.run(debug=False)
|