நமது algorithm கணிக்கும் மதிப்பினை ஒரு API-ஆக expose செய்வதற்கு Flask பயன்படுகிறது. இதற்கான நிரல் பின்வருமாறு.
This file contains 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 os | |
import json | |
import pandas as pd | |
import numpy | |
from flask import Flask, render_template, request, jsonify | |
from pandas.io.json import json_normalize | |
from sklearn.externals import joblib | |
app = Flask(__name__) | |
port = int(os.getenv('PORT', 5500)) | |
@app.route('/') | |
def home(): | |
return render_template('index.html') | |
@app.route('/api/salepricemodel', methods=['POST']) | |
def salepricemodel(): | |
if request.method == 'POST': | |
try: | |
post_data = request.get_json() | |
json_data = json.dumps(post_data) | |
s = pd.read_json(json_data) | |
p = joblib.load("./salepricemodel.pkl") | |
r = p.predict(s) | |
return str(r) | |
except Exception as e: | |
return (e) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=port, debug=True) |
நிரலுக்கான வெளியீடு:
* Serving Flask app “flask_api” (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 690-746-333
* Running on 0.0.0.0:5500/ (Press CTRL+C to quit)
இதனை postman எனும் கருவி மூலம் நாம் சோதித்துக் கொள்ளலாம்.