Created
June 2, 2022 18:41
-
-
Save kusal1990/f4a018dfdc15d835e471299d47c573e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok