Deploying an ML model on an AWS EC2 instance using a Flask API and applying user input to the ML model via AWS IoT Core

0

How to send AWS IoT core data to ML model which is already deployed on AWS EC2 instance by using Flask API??

I have to deploy my ML model on AWS ec2-instance by using Flask API and make public URL like as :' http://ec2-16-171-143-........compute.amazonaws.com:8080'.

I also connect my hardware IoT device with AWS IoT core, and properly getting data on IOT core. Then, I have to make a AWS Lambda function and triggering Lambda function by IOT core. Hence I tried to send data to Flask api(web address), but failed.

I have to used 'app.py' code and 'index.html' for deploying ML model to AWS ec2 instance using Flask API.

The Lambda Function is triggering properly by AWS iot Core ,but couldn't send data to Flask API URL!!!! No error finding after running code ,but not showing any data on web address.

I want to send data to Flask api web address, apply ML model on the data and get predicted result, finally show the predicted result on the web to user.

Nusrat
asked 3 months ago201 views
1 Answer
1

Hello.

Are connections from Lambda recorded in the access logs on the Flask API side?
If it is recorded, there may be a problem with the processing on the Flask API side.

profile picture
EXPERT
answered 3 months ago
  • No ,it is not recorded. Please correct my Flask API code which is deployed on AWS ec2 instance for receiving data from AWS lambda function and show the incoming data and predicted result on the web. Here is my code:

    from flask import Flask, request, render_template, session, redirect, url_for
    

    import logging import pickle app = Flask(name) model = pickle.load(open('model.pkl', 'rb')) @app.route('/') def home(): return render_template('index.html') @app.route('/api', methods=['POST']) def api(): data = request.get_json() cg = data['CGPA'] iq = data['IQ'] ps = data['Profile Score'] session['cg'] = cg session['iq'] = iq session['ps'] = ps return redirect(url_for('result')) @app.route('/result') def result(): try: cg = session.get('cg') iq = session.get('iq') ps = session.get('ps') cg = float(cg) iq = float(iq) ps = float(ps) prediction = model.predict([[cg, iq, ps]]) predicted_result = prediction[0].item()
    result_data = { 'CGPA': cg, 'IQ': iq, 'Profile Score': ps, 'Predicted Result': predicted_result } return render_template('result.html',result=result_data)

    if name == 'main': app.run(host='0.0.0.0', port=8084)

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions