コード例 #1
0
ファイル: app.py プロジェクト: nilmosos/prueba
def predict():
    form = PredictForm()
    if form.submit():

        #API_KEY = "<IBM Cloud API key>"    #Select Account > Users, go to Manage > Access (IAM) > API keys.
        API_KEY = "GjBEDX7Pq5jMNaP97G9XbYDX_nhU2EO3HOgRvYibRFg6"
        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}

        if( form.case.data == None and form.symptoms_start_date.data == None  and form.diagnosys_date.data == None  and 
            form.city.data == None  and form.locality.data == None  and  form.age.data == None  and  form.age_unit.data == None  and  form.sex.data == None  and 
            form.contagion_type.data == None  and  form.current_location.data == None ): 
          python_object = []
        else:
          python_object = [form.case.data, form.symptoms_start_date.data, form.diagnosys_date.data,
            form.city.data, form.locality.data, form.age.data, form.age_unit.data, form.sex.data,
            form.contagion_type.data, form.current_location.data ]
        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {"input_data": [{"fields": ["case", "symptoms_start_date", "diagnosys_date",
          "city", "locality", "age", "age_unit", "sex", "contagion_type", "current_location" ], "values": userInput }]}

        print(payload_scoring)
        # response_scoring = requests.post("https://us-south.ml.cloud.ibm.com/ml/v4/deployments/<deployment-id-goes-here>/predictions?version=<DATE>", json=payload_scoring, headers=header)
        response_scoring = requests.post('https://us-south.ml.cloud.ibm.com/ml/v4/deployments/2aa265c9-4684-4ae6-8d75-fd998592f5b8/predictions?version=2021-04-30', json=payload_scoring, headers={'Authorization': 'Bearer ' + mltoken})

        output = json.loads(response_scoring.text)
        print("Salida")
        print(output)
        print("Salida")


        form.abc = ""
        if 'predictions' in output.keys():
          ab = output['predictions']
          for key in ab[0]:
            bc = ab[0][key]
          # form.abc = roundedCharge # this returns the response back to the front page
          form.abc = bc[0][0] # this returns the response back to the front page
        
        return render_template('index.html', form=form)
def predict():
    form = PredictForm()
    if form.submit():

        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {
            'Content-Type':
            'application/json',
            'Authorization':
            'Bearer ' +
            "eyJraWQiOiIyMDIwMTEyMTE4MzQiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJJQk1pZC01NTAwMDhSV0FOIiwiaWQiOiJJQk1pZC01NTAwMDhSV0FOIiwicmVhbG1pZCI6IklCTWlkIiwianRpIjoiZWZjNjRiZGEtNjg5NS00NDM0LWFjMGUtMzcwMTU0MDE5YzIzIiwiaWRlbnRpZmllciI6IjU1MDAwOFJXQU4iLCJnaXZlbl9uYW1lIjoiUml0dSIsImZhbWlseV9uYW1lIjoicmFqIiwibmFtZSI6IlJpdHUgcmFqIiwiZW1haWwiOiI0bmkxOGlzMDcxX2JAbmllLmFjLmluIiwic3ViIjoiNG5pMThpczA3MV9iQG5pZS5hYy5pbiIsImFjY291bnQiOnsidmFsaWQiOnRydWUsImJzcyI6IjkzZWI1YzY4NDc4YjQ5N2NhZGZmZTg5NzE2ZDBlM2Y3IiwiZnJvemVuIjp0cnVlfSwiaWF0IjoxNjA3ODY5MTUwLCJleHAiOjE2MDc4NzI3NTAsImlzcyI6Imh0dHBzOi8vaWFtLmJsdWVtaXgubmV0L2lkZW50aXR5IiwiZ3JhbnRfdHlwZSI6InVybjppYm06cGFyYW1zOm9hdXRoOmdyYW50LXR5cGU6YXBpa2V5Iiwic2NvcGUiOiJpYm0gb3BlbmlkIiwiY2xpZW50X2lkIjoiZGVmYXVsdCIsImFjciI6MSwiYW1yIjpbInB3ZCJdfQ.bHf38EPnx79HiUky8kx48ZT3n47twChQBZ7EtMNiV6IYq26vZf9boRhl7cH2un1ec_bTn9mlTVbeR5Z9D5GejpbK6cV-bbQvAxyhQeO_8QxOakTbVjrb7XB0fJq6H0cTw3g4VgN2iPM0GmSkmUqG4nHcttkA6GIX38qTRi0vwv5Y4fq-uiQ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lnlxCaHbbpbyizsFbMai0canDQ1sykPoTlAuhKd2QYAG5MonfRPsBEMxOMIt_otgKQ5uljRZWCgjYCFdogyQ-oaEyHYCVaAvYgjhCkVYihzs6Qnv1BQ8y-pWV9j6gcBYybxm3X57x6k2Jtk0hZdbjbBko3fOE8PTnqZ4lDLTFsPUdDqkPsjS3P_W7ZpT0XEcqByZmda1pxoqdm3yt3-nfmxHVUt_fQV1lmqmnLv8Ssw"
        }

        python_object = [
            int(form.Pregnancies.data),
            int(form.Glucose.data),
            int(form.BloodPressure.data),
            int(form.SkinThickness.data),
            int(form.Insulin.data),
            float(form.BMI.data),
            float(form.DiabetesPedigreeFunction.data),
            int(form.Age.data)
        ]
        #Transform python objects to  Json
        #print(python_object)
        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {
            "input_data": [{
                "fields": [
                    "Pregnancies", "Glucose", "BloodPressure", "SkinThickness",
                    "Insulin", "BMI", "DiabetesPedigreeFunction", "Age"
                ],
                "values":
                userInput
            }]
        }
        #print(payload_scoring)
        response_scoring = requests.post(
            "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/167da3fa-d770-4b95-b318-46e6b9846d5c/predictions?version=2020-12-13",
            json=payload_scoring,
            headers=header)
        #print(response_scoring.text)
        output = json.loads(response_scoring.text)
        #print(output)
        for key in output:
            ab = output[key]

        for key in ab[0]:
            bc = ab[0][key]

        #print(bc)

        form.abc = bc[0][0]  # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #3
0
def predict():
    form = PredictForm()
    if form.submit():

        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {
            'Content-Type': 'application/json',
            'Authorization':
            'Bearer ' + " TODO: ADD YOUR IAM ACCESS TOKEN FROM IBM CLOUD HERE",
            'ML-Instance-ID': " TODO: ADD YOUR ML INSTANCE ID HERE "
        }

        if (form.bmi.data == None):
            python_object = []
        else:
            python_object = [
                form.age.data, form.sex.data,
                float(form.bmi.data), form.children.data, form.smoker.data,
                form.region.data
            ]
        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {
            "input_data": [{
                "fields":
                ["age", "sex", "bmi", "children", "smoker", "region"],
                "values":
                userInput
            }]
        }

        response_scoring = requests.post(
            "https://us-south.ml.cloud.ibm.com/v4/deployments/ADD-DEPLOYMENT-ID-HERE/predictions",
            json=payload_scoring,
            headers=header)

        output = json.loads(response_scoring.text)

        for key in output:
            ab = output[key]

        for key in ab[0]:
            bc = ab[0][key]

        roundedCharge = round(bc[0][0], 2)

        form.abc = roundedCharge  # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #4
0
def predict():
    form = PredictForm()
    if form.submit():

        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {
            'Content-Type':
            'application/json',
            'Authorization':
            'Bearer ' +
            "eyJraWQiOiIyMDIwMTEyMTE4MzQiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJJQk1pZC01NTAwMDhSV0FOIiwiaWQiOiJJQk1pZC01NTAwMDhSV0FOIiwicmVhbG1pZCI6IklCTWlkIiwianRpIjoiY2EyZmY5M2UtYTBkNi00Zjg0LTljZDgtYjcyZTJjYWE2ODIzIiwiaWRlbnRpZmllciI6IjU1MDAwOFJXQU4iLCJnaXZlbl9uYW1lIjoiUml0dSIsImZhbWlseV9uYW1lIjoicmFqIiwibmFtZSI6IlJpdHUgcmFqIiwiZW1haWwiOiI0bmkxOGlzMDcxX2JAbmllLmFjLmluIiwic3ViIjoiNG5pMThpczA3MV9iQG5pZS5hYy5pbiIsImFjY291bnQiOnsidmFsaWQiOnRydWUsImJzcyI6IjkzZWI1YzY4NDc4YjQ5N2NhZGZmZTg5NzE2ZDBlM2Y3IiwiZnJvemVuIjp0cnVlfSwiaWF0IjoxNjA3NzEyNDI4LCJleHAiOjE2MDc3MTYwMjgsImlzcyI6Imh0dHBzOi8vaWFtLmJsdWVta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Kz-pG8DRdoagotIt7uerClwbNKjqfCTE3kScwyhnFx-hFOIdjoa5Cwsmwy8A6DYR0rdMNVLU4M2DI8N7_8YJAViKvP0WJYaMr0mUPdNF-qJ2ffP4eazknnG7yilmjEq3tOZgXrpAY1k1ZdHpg0xh-1S_uyIkpG9Wr26He3u_FwNNnVki9tvPElFuDtsSXqOyoAPHB0s88jatAd_kf03fBYNW3QdNxDEr6W5-iXWW8UDdsjDGZpMYPi0OIrevnCgTpwg5QYq13l4608w85Cx14Lhm3mupzvN_pHroLIzfDW7iQWQVMq17WTBYndbLKIEea7mre1J_7xpR-W0i1yqKZwH_5vsSnlva77KXlIeW_XBVoYCHyCQeKfAOR4YUQtMINB54ZBqwyKtvBx_R68U5yqwoTf7lsXZqCPSJ34OqSHFHaTDRPEPNa3FAo8PDeEgGPdRsDuN3Q0gXgqZKs3NTF4V-odcM2jr2fzdiYq9XpmMP0Pp0Kxo29OBpfnMQYo6QbY71by9tHYIp1T7bdeDYGFwQM-pulTcV7-gjWFl4tU1dw1lShfXRFqkwFbQmqTy1DG8SWisVD3S7yyHjOP3dc2xdtg"
        }

        python_object = [
            float(form.Wind_Speed.data),
            float(form.Theoretical_Power_Curve.data),
            float(form.Wind_Direction.data)
        ]
        #Transform python objects to  Json
        #print(python_object)
        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {
            "input_data": [{
                "fields": [
                    "Wind Speed (m/s)", "Theoretical_Power_Curve (KWh)",
                    "Wind Direction (°)"
                ],
                "values":
                userInput
            }]
        }
        #print(payload_scoring)
        response_scoring = requests.post(
            "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/685d0d82-7b7c-4bcb-bf36-05446c46c097/predictions?version=2020-11-30",
            json=payload_scoring,
            headers=header)
        print(response_scoring.text)
        output = json.loads(response_scoring.text)
        #print(output)
        for key in output:
            ab = output[key]

        for key in ab[0]:
            bc = ab[0][key]

        form.abc = bc[0][0]  # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #5
0
ファイル: app.py プロジェクト: aradmifi/Fraud-Detector
def predict():
    form = PredictForm()
    if form.submit():

        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' +
            "eyJraWQiOiIyMDIwMDcyNDE4MzEiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJpYW0tU2VydmljZUlkLTlmMTFhNzNkLWI1N2QtNGFhNy1iZTE0LTI3NzY4ZWVmODUzYyIsImlkIjoiaWFtLVNlcnZpY2VJZC05ZjExYTczZC1iNTdkLTRhYTctYmUxNC0yNzc2OGVlZjg1M2MiLCJyZWFsbWlkIjoiaWFtIiwiaWRlbnRpZmllciI6IlNlcnZpY2VJZC05ZjExYTczZC1iNTdkLTRhYTctYmUxNC0yNzc2OGVlZjg1M2MiLCJuYW1lIjoid2RwLXdyaXRlciIsInN1YiI6IlNlcnZpY2VJZC05ZjExYTczZC1iNTdkLTRhYTctYmUxNC0yNzc2OGVlZjg1M2MiLCJzdWJfdHlwZSI6IlNlcnZpY2VJZCIsImFjY291bnQiOnsidmFsaWQiOnRydWUsImJzcyI6ImU4NmQ3YzU5OTA5MTkwYzg4ZGIzZDZjNjBhYWY1NTRkIiwiZnJvemVuIjp0cnVlfSwiaWF0IjoxNTk2MjA0NDczLCJleHAiOjE1OTYyMDgwNzMsImlzcyI6Imh0dHBzOi8vaWFtLmJsdWVtaXgubmV0L2lkZW50aXR5IiwiZ3JhbnRfdHlwZSI6InVybjppYm06cGFyYW1zOm9hdXRoOmdyYW50LXR5cGU6YXBpa2V5Iiwic2NvcGUiOiJpYm0gb3BlbmlkIiwiY2xpZW50X2lkIjoiZGVmYXVsdCIsImFjciI6MSwiYW1yIjpbInB3ZCJdfQ.Jza_BjwI9OstNsFj8G8fD3IfW3X_1_zAP1pwcUfKp-DsYxj9d07d4b2flIiM_wFjDS2ylxn7SI7nTBRGC9Fe2jMBqMUWQDkhsqA1g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7T2Q0zB9OjL1q5q7ddrXabQTFu3Jxazrapj7XsBt3uHQ6a6nF8LIb5gBktDNEsFs6XIk-e9TIzwJImsErsa9b95kKWunQr3Tom5idhsUkRMScxZUNllUGopOtfTyAR_kNkBykKsDMtKoBTY6BTEy_TIuOZLFWOGEWDSojwms_ctvwfBzAUD0mT2W20gw53sqNsozpJpbFqplYSP5at6R3I3EQ3s9M96Iu_2Y6PV8uszXd0eucxvgY27orq6fdP6MMEqShf3ScFgVQNEGiSc",
            'ML-Instance-ID': "61862e37-c7bc-4fae-9d6e-5dc33e3d5700"
        }

        if (form.ID_Txn.data == None):
            python_object = []
        else:
            #float(form.bmi.data)
            python_object = [
                int(form.ID_Txn.data), form.Hora_Txn.data, form.Sexo.data,
                form.Edo_Civil.data, form.Hijos.data, form.Monto_Txn.data,
                form.Establecimiento.data, form.Tipo_Compra.data,
                form.Metodo_Pago.data, form.Edad.data
            ]
        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {
            "input_data": [{
                "fields": [
                    "ID_Txn", "Hora_Txn", "Sexo", "Edo_Civil", "Hijos",
                    "Monto_Txn", "Establecimiento", "Tipo_Compra",
                    "Metodo_Pago", "Edad"
                ],
                "values":
                userInput
            }]
        }

        response_scoring = requests.post(
            "https://us-south.ml.cloud.ibm.com/v4/deployments/4c8b8b97-954b-4238-b09c-1d9276f8a39d/predictions",
            json=payload_scoring,
            headers=header)

        output = json.loads(response_scoring.text)
        print(output)

        form.abc = output  # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #6
0
def predict():
    form = PredictForm()
    if form.submit():
        # NOTE: you should not use your apikey in plain text consider using iam_token directly in PROD enviroments.
        API_KEY = "j_iFO1lfw14_IltudzUFHu-2IElu32oM1ip1pzsJTb77"
        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"]
        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + "eyJraWQiOiIyMDIxMDQyMDE4MzYiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJJQk1pZC02NjIwMDFWM1FSIiwiaWQiOiJJQk1pZC02NjIwMDFWM1FSIiwicmVhbG1pZCI6IklCTWlkIiwianRpIjoiYThhN2UyN2QtNDllOC00OGFjLTkxNTMtZDg2NjVjZmRiZjA3IiwiaWRlbnRpZmllciI6IjY2MjAwMVYzUVIiLCJnaXZlbl9uYW1lIjoiU2FudGlhZ28iLCJmYW1pbHlfbmFtZSI6IlJpb3MiLCJuYW1lIjoiU2FudGlhZ28gUmlvcyIsImVtYWlsIjoic2FudGlhZ28ucmlvc29AdWRlYS5lZHUuY28iLCJzdWIiOiJzYW50aWFnby5yaW9zb0B1ZGVhLmVkdS5jbyIsImF1dGhuIjp7InN1YiI6InNhbnRpYWdvLnJpb3NvQHVkZWEuZWR1LmNvIiwiaWFtX2lkIjoiaWFtLTY2MjAwMVYzUVIiLCJuYW1lIjoiU2FudGlhZ28gUmlvcyIsImdpdmVuX25hbWUiOiJTYW50aWFnbyIsImZhbWlseV9uYW1lIjoiUmlvcyIsImVtYWlsIjoic2FudGlhZ28ucmlvc29AdWRlYS5lZHUuY28ifSwiYWNjb3VudCI6eyJ2YWxpZCI6dHJ1ZSwiYnNzIjoiYTQ5OGQ4N2I1YWJmNGM1Zjg0NzMzNWM2ZjA1MGY5NzMiLCJmcm96ZW4iOnRydWV9LCJpYXQiOjE2MTk5MDc3MzAsImV4cCI6MTYxOTkxMTMzMCwiaXNzIjoiaHR0cHM6Ly9pYW0uY2xvdWQuaWJtLmNvbS9vaWRjL3Rva2VuIiwiZ3JhbnRfdHlwZSI6InVybjppYm06cGFyYW1zOm9hdXRoOmdyYW50LXR5cGU6YXBpa2V5Iiwic2NvcGUiOiJpYm0gb3BlbmlkIiwiY2xpZW50X2lkIjoiZGVmYXVsdCIsImFjciI6MSwiYW1yIjpbInB3ZCJdfQ.Of3dCuqM-reK7X9CGqlss1lJ7L8sJL5TbWfLTLkHcTZ7B8f2iht7FyUx6RNIE5jTArIBlO7ni4BRyMVR4dFOeUs0-U9uPdiupPdtnCHA2XnMpaLDPE7vNNgeLyqs1AEaKm_4U7MRMTWdVwQxFCbFoK1fuu1Z-Cw5r_CErpu1ucaooNQneLa4ejYL-Vh3DpLGcCF-kQjaJFxiBZvcfr2TGbFHS4Cr68FZ4lSFgztxF7id0dEhT7kO8Vk7bfftdfFrwzYHXuTaK0Gdly_3GU4bjz6b4vnixqS9iG_fcjsrwF8BGAoAHo-8khvmHPCjV_QLgNcsNfN8ze_MrymLcFgggA"}

        if(form.MesVencimiento.data == None): 
          python_object = []
        else:
          # form.Unnamed=1
          python_object = [form.Unnamed.data,form.Cliente.data, form.Pais.data,form.Moneda.data,form.Unidad.data, 
            form.MesVencimiento.data,form.Monto.data, form.plazo.data,float(form.Prob_D.data)]
        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {"input_data": [{"fields":    ["Unnamed: 0",
				"Cliente",
				"Pais",
				"Moneda",
				"Unidad",
				"MesVencimiento",
				"Monto",
				"plazo",
				"Prob_D"], "values": userInput }]}

        response_scoring = requests.post("https://us-south.ml.cloud.ibm.com/ml/v4/deployments/37264cc6-49e9-496a-bf4e-a955f07affe4/predictions?version=2021-05-01", json=payload_scoring, headers=header)

        output = json.loads(response_scoring.text)
        print(output)
        for key in output:
          ab = output[key]
        

        for key in ab[0]:
          bc = ab[0][key]
        
        roundedCharge = round(bc[0][0],2)
        if roundedCharge == 1 :
              respuesta="Si entrara en default"
        else: 
          respuesta="Es probable que no entre en default"
        form.abc = respuesta # this returns the response back to the front page
        form.ammount=form.Prob_D.data*form.Monto.data
        return render_template('index.html', form=form)
def predict():
    form = PredictForm()
    if form.submit():

        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {
            'Content-Type':
            'application/json',
            'Authorization':
            'Bearer ' +
            "eyJraWQiOiIyMDIwMTEyMTE4MzQiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJJQk1pZC01NTAwMDhISlc4IiwiaWQiOiJJQk1pZC01NTAwMDhISlc4IiwicmVhbG1pZCI6IklCTWlkIiwianRpIjoiMzVmMDMwOTgtMjVlMy00ZmI3LWJlNDItODQ0MGI3MGIwMmQ5IiwiaWRlbnRpZmllciI6IjU1MDAwOEhKVzgiLCJnaXZlbl9uYW1lIjoiQWJoaW5hdiIsImZhbWlseV9uYW1lIjoiS3VtYXIiLCJuYW1lIjoiQWJoaW5hdiBLdW1hciIsImVtYWlsIjoiNG5pMThpczAwNV9iQG5pZS5hYy5pbiIsInN1YiI6IjRuaTE4aXMwMDVfYkBuaWUuYWMuaW4iLCJhY2NvdW50Ijp7InZhbGlkIjp0cnVlLCJic3MiOiJmZmE0OWE0NGZmNjg0MGJiOTc0YWYyMmI5NDlkMTgyYyIsImZyb3plbiI6dHJ1ZX0sImlhdCI6MTYwODE4NDkxOSwiZXhwIjoxNjA4MTg4NTE5LCJpc3MiOiJodHRwczovL2lhbS5ibHVlbWl4Lm5ldC9pZGVudGl0eSIsImdyYW50X3R5cGUiOiJ1cm46aWJtOnBhcmFtczpvYXV0aDpncmFudC10eXBlOmFwaWtleSIsInNjb3BlIjoiaWJtIG9wZW5pZCIsImNsaWVudF9pZCI6ImRlZmF1bHQiLCJhY3IiOjEsImFtciI6WyJwd2QiXX0.aRyTDRa4-m6jMdsStWtrOI51oVewxDAPaUDykEU6L4B75Q3eWJ5BcmKavKFKwXhySrs4XUpU1zAxTr7-l5awLMYJVoLfR2L7wC7_GlDTShEPSvoX_jUyyekMMKzAIshP_utV5LzEhJs4klzBLOfSuQTlh49PKodhGPIy8njEnLSbPu-NRwb01W-E3si2I1w3wPM_u_gUCnWPBljThaoLrLC28VqSDOFL67H2fK-lpVsKFV5j-P14g7dm2ckdxqUYFrhIgeAKdHtAuHx1njXaffo0dAZmooYaaP_6gI_Ajh1WFgegeAnfkA7kEpvYaQIQN07SEgmnMRrYVXdO_xx8rQ"
        }
        python_object = [
            float(form.Wind_Speed.data),
            float(form.Theoretical_Power_Curve.data),
            float(form.Wind_Direction.data)
        ]
        #Transform python objects to  Json
        #print(python_object)
        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {
            "input_data": [{
                "fields": [
                    "Wind Speed (m/s)", "Theoretical_Power_Curve (KWh)",
                    "Wind Direction (°)"
                ],
                "values":
                userInput
            }]
        }
        #print(payload_scoring)
        response_scoring = requests.post(
            "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/e42cf888-7ee0-4a9c-bddc-3c4adf3fa2cb/predictions?version=2020-12-14",
            json=payload_scoring,
            headers=header)
        print(response_scoring.text)
        output = json.loads(response_scoring.text)
        #print(output)
        for key in output:
            ab = output[key]

        for key in ab[0]:
            bc = ab[0][key]

        form.abc = bc[0][0]  # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #8
0
def predict():
    form = PredictForm()
    if form.submit():
        # NOTE: you should not use your apikey in plain text consider using iam_token directly in PROD enviroments.
        API_KEY = "<Your APIKEY here>"
        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"]
        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + mltoken}

        if(form.bmi.data == None): 
          python_object = []
        else:
          python_object = [form.age.data, form.sex.data, float(form.bmi.data),
            form.children.data, form.smoker.data, form.region.data]
        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {"input_data": [{"fields": ["age", "sex", "bmi",
          "children", "smoker", "region"], "values": userInput }]}

        response_scoring = requests.post("https://us-south.ml.cloud.ibm.com/ml/v4/deployments/<Your deployment ID here>/predictions?version=2020-09-01", json=payload_scoring, headers=header)

        output = json.loads(response_scoring.text)
        print(output)
        for key in output:
          ab = output[key]
        

        for key in ab[0]:
          bc = ab[0][key]
        
        roundedCharge = round(bc[0][0],2)

  
        form.abc = roundedCharge # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #9
0
def predict():
    form = PredictForm()
    if form.submit():

        # NOTE: generate iam_token and retrieve ml_instance_id based on provided documentation
        header = {'Content-Type': 'application/json', 'Authorization': 'Bearer '
                 + "eyJraWQiOiIyMDIwMDUyNTE4MzAiLCJhbGciOiJSUzI1NiJ9.eyJpYW1faWQiOiJpYW0tU2VydmljZUlkLTIzMWI5OTYyLWExN2ItNDI3OC05YmY3LTQ3Y2RkMDgwYjc2ZCIsImlkIjoiaWFtLVNlcnZpY2VJZC0yMzFiOTk2Mi1hMTdiLTQyNzgtOWJmNy00N2NkZDA4MGI3NmQiLCJyZWFsbWlkIjoiaWFtIiwiaWRlbnRpZmllciI6IlNlcnZpY2VJZC0yMzFiOTk2Mi1hMTdiLTQyNzgtOWJmNy00N2NkZDA4MGI3NmQiLCJuYW1lIjoid2RwLXdyaXRlciIsInN1YiI6IlNlcnZpY2VJZC0yMzFiOTk2Mi1hMTdiLTQyNzgtOWJmNy00N2NkZDA4MGI3NmQiLCJzdWJfdHlwZSI6IlNlcnZpY2VJZCIsImFjY291bnQiOnsidmFsaWQiOnRydWUsImJzcyI6IjkzZWFmZDU2MjNlYTRjMGFhNWYwOWVmOTQ1MjkxOGEyIn0sImlhdCI6MTU5MTYzMTIxOCwiZXhwIjoxNTkxNjM0ODE4LCJpc3MiOiJodHRwczovL2lhbS5ibHVlbWl4Lm5ldC9pZGVudGl0eSIsImdyYW50X3R5cGUiOiJ1cm46aWJtOnBhcmFtczpvYXV0aDpncmFudC10eXBlOmFwaWtleSIsInNjb3BlIjoiaWJtIG9wZW5pZCIsImNsaWVudF9pZCI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sXIpmVCaFBw1ZuMjOQZ14dz_ugvkI7sy0N0P0SuFM5Ppx_07H2X5bcQa3CQRWYSOM9DdCcHhojE8xvgQzpTOPBvayoA58DosN03r7Jffz0wtAow4kYPl8_GQYfFA5t5AUONNHrIe7RC1d76NAZBSJElgQzdv7oQIdSAdjAKUR3B1WJ-LcmiX2wFoaR0-Ecxhgo130-J0BCbHoRk73OSxGmFfHVNPVlo0wbpYbOLOgdMBisCkRsmh1eI54OKPSXkuJ-LjXHyALIxu9ewhkuj-eKo_IXSMwmBDN1Z3rMvA3GQu8hcWjxZYcVb5DU_0-M-3ZMPYm8BNd9-Swwmh3bUtpe3u9PkAN4k_I0GOknwJp8nAANsBNHeoxi64rw",
                  'ML-Instance-ID': "9c3b2402-9562-439e-8df2-9545ed40c34a"}

        if(form.ingreso_mensual.data == None): 
          python_object = []
        else:
          python_object = [form.edad.data, form.estado_civil.data, float(form.ingreso_mensual.data),
            form.anios_laboral.data, form.hijos.data, form.region.data]
        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # NOTE: manually define and pass the array(s) of values to be scored in the next line
        payload_scoring = {"input_data": [{"fields": ["edad", "estado_civil", "ingreso_mensual",
          "anios_laboral", "hijos", "region"], "values": userInput }]}

        response_scoring = requests.post("https://us-south.ml.cloud.ibm.com/v4/deployments/c2f3ae93-dfce-4ce6-8eb5-9378209a7e35/predictions", json=payload_scoring, headers=header)

        output = json.loads(response_scoring.text)
        print(output)
        for key in output:
          ab = output[key]
        

        for key in ab[1]:
          bc = ab[0][key]
        
        roundedCharge = round(bc[0][0],2)

  
        form.abc = roundedCharge # this returns the response back to the front page
        return render_template('index.html', form=form)
コード例 #10
0
def predict():
    form = PredictForm()
    if form.submit():

        if (form.antigen.data == None):
            python_object = []
        else:
            python_object = [
                int(form.patient_age_quantile.data),
                int(form.patient_addmited_to_regular.data),
                int(form.patient_addmited_to_semi_intense.data),
                int(form.patient_addmited_to_intense.data),
                float(form.platelets.data),
                float(form.mean_platelet_volume.data),
                float(form.red_blood_cells.data),
                float(form.lymphocytes.data),
                float(form.mean_corpuscular_hemoglobin_concentration.data),
                float(form.leukocytes.data),
                float(form.basophils.data),
                float(form.eosinophils.data),
                float(form.mean_corpuscular_volum.data),
                float(form.monocytes.data),
                float(form.red_blood_cell_distribution_width.data),
                int(form.antigen.data)
            ]

        #Transform python objects to  Json

        userInput = []
        userInput.append(python_object)

        # # NOTE: manually define and pass the array(s) of values to be scored in the next line
        test_value = {
            "input_data": [{
                "fields": [
                    "patient_age_quantile", "patient_addmited_to_regular",
                    "patient_addmited_to_semi_intense",
                    "patient_addmited_to_intense", "platelets",
                    "mean_platelet_volume", "red_blood_cells", "lymphocytes",
                    "mean_corpuscular_hemoglobin_concentration", "leukocytes",
                    "basophils", "eosinophils", "mean_corpuscular_volum",
                    "monocytes", "red_blood_cell_distribution_width", "antigen"
                ],
                "values":
                userInput
            }]
        }

        test_value["input_data"][0]["values"][0][0] = get_age(
            int(test_value["input_data"][0]["values"][0][0]))
        print(test_value)

        output = makeRequest(test_value, _run_on_start.first_token)

        for key in output:
            ab = output[key]

        for key in ab[0]:
            bc = ab[0][key]

        if (bc[0][0] == 0):
            result = "Negative to Covid-19 Test"
            confident = "Condifident of : " + str(round(bc[0][1][0], 3))
        else:
            result = "Positve to Covid-19 Test "
            confident = "Condifident of : " + str(round(bc[0][1][1], 3))

        print(result)

        form.abc = result
        form.confi = confident
        return render_template('index.html', form=form)
コード例 #11
0
ファイル: app.py プロジェクト: Anughag/NLP_Python_Flask
def predict():
    form = PredictForm()
    if form.submit():
      SearchStr=form.num1.data
      TOD="Business Logic"
          
    k=0
          
    for a in df.index:

        X=df['Desc'][a]
        # tokenization 


        X_list = word_tokenize(X.lower())  
        Y_list = word_tokenize(SearchStr.lower()) 


      # Fetching all stop words
        sw = stopwords.words('english')  
        V1 =[];V2 =[] 


        # Stop word removal 
        X_set = {lemmatizer.lemmatize(w) for w in X_list if not w in sw}  
        Y_set = {lemmatizer.lemmatize(w) for w in Y_list if not w in sw} 


        UV = X_set.union(Y_set)  
        for w in UV:


            if w in X_set: V1.append(1) 


            else: V1.append(0) 
            if w in Y_set: V2.append(1) 
            else: V2.append(0) 
            c = 0
       
            

            
    # Calculating cosine similarity  
        for i in range(len(UV)): 


          c+= V1[i]*V2[i] 
         
        cosine = c / float((sum(V1)*sum(V2))**0.5) 
        
        
        Final.loc[Final['Defect_desc']== X,'Similarity']=cosine
        df_Final=Final.copy()
        

          #sum=form.num1.data+form.num2.data
        df_Final=Final[(Final['Similarity']>0) & (Final['Type of Defect']==TOD)].sort_values(by='Similarity',ascending=False).head(3).head(3)
        #print(df_Final)
        df_Final=pd.DataFrame.to_html(df_Final)
        #print(df_Final)
        form.abc=df_Final
        #print(form.abc)
        pd.show_versions()
    return render_template('index.html', form=form)