-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
57 lines (47 loc) · 2.16 KB
/
app.py
1
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Created on Sat Jul 31 12:50:40 2021@author: fasil"""from flask import Flask, request, render_templateimport requestsapp = Flask(__name__)API_KEY = "uu5F17zBZUwQbUxxqbnKBcp2gXt3tJXPxfaEOpgDUTL4"token_response = requests.post('https://iam.cloud.ibm.com/identity/token', data={"apikey": API_KEY, "grant_type": 'urn:ibm:params:oauth:grant-type:apikey'})mltoken = token_response.json()["access_token"]header = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + mltoken}@app.route('/')def home(): return render_template('index.html')@app.route('/prediction', methods=['POST'])def prediction(): option = [[int(x) for x in request.form.values()]] if option[0][0] == 2: del option[0][0] x_test = option print(x_test) payload_scoring = {"input_data": [{"field": [["year", "month", "day"]], "values": x_test}]} response_scoring = requests.post( 'https://us-south.ml.cloud.ibm.com/ml/v4/deployments/efde5787-7fe6-44ed-b6ae-7602c8004740/predictions?version=2021-08-03', json=payload_scoring, headers={'Authorization': 'Bearer ' + mltoken}) print("Scoring response") prediction_ = response_scoring.json() pred = prediction_['predictions'][0]['values'][0][0] output = 'Gas Price for the given date is: {} Dollars'.format(pred) else: del option[0][0] x_test = option print(x_test) payload_scoring = {"input_data": [{"field": [["year", "month", "day"]], "values": x_test}]} response_scoring = requests.post( 'https://us-south.ml.cloud.ibm.com/ml/v4/deployments/3ff71c4f-5d42-4b2b-8089-de3380e43850/predictions?version=2021-08-03', json=payload_scoring, headers={'Authorization': 'Bearer ' + mltoken}) print("Scoring response") prediction_ = response_scoring.json() pred = prediction_['predictions'][0]['values'][0][0] output = 'Gas Price for the given date is: {} Dollars'.format(pred) return render_template('index.html', predic_text=output)if __name__ == "__main__": app.run(debug=True)