Skip to content

Instantly share code, notes, and snippets.

@kusal1990
Created June 2, 2022 18:41
Show Gist options
  • Save kusal1990/f4a018dfdc15d835e471299d47c573e5 to your computer and use it in GitHub Desktop.
Save kusal1990/f4a018dfdc15d835e471299d47c573e5 to your computer and use it in GitHub Desktop.
import flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/index8050')
def index8050():
return flask.render_template('index8050.html')
@app.route('/predict', methods=['POST'])
def predict():
try:
step_dim=160
max_num = 127
min_num = -128
meta_data=pd.read_csv("df_metadata_sample.csv")
signal_data=pq.read_pandas('sample_signal_data.parquet').to_pandas()
if (signal_data[(signal_data > 127)].any()).any()==True:
return jsonify("Error!, Amplitude value is too high")
elif (signal_data[(signal_data < -128)].any()).any()==True:
return jsonify("Error!, Amplitude value is too low")
elif (signal_data.isnull().values.any())==True:
return jsonify("Error!, Amplitude value is missing")
else:
clf = load_model('model.h5',
custom_objects={'Attention': Attention(step_dim),
'GlorotUniform':glorot_uniform
,'LSTMCell':LSTMCell,
'matthews_correlation':matthews_correlation})
x_test=data_processing(meta_data,signal_data)
pred = clf.predict(x_test)
prediction=[]
for index,i in enumerate(pred):
if i<0.5:
prediction.append("Partial discharge is not there for the signal")
else:
prediction.append("Partial discharge is there for the signal")
return jsonify({'prediction': prediction})
except :
return jsonify("File name is wrong.Try after proper file renameing")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8050)
@kusal1990
Copy link
Author

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment