Skip to content

Commit

Permalink
model
Browse files Browse the repository at this point in the history
  • Loading branch information
aakriti1318 committed Nov 7, 2022
1 parent b763570 commit 062cc22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
28 changes: 14 additions & 14 deletions azure_functions/GetRecommendations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import logging

import json
import azure.functions as func

from utils.predict import predict_fun

def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
def main(req: func.HttpRequest) -> func.HttpResponse:
req_body = req.get_json()
n = req_body.get('n')
p = req_body.get('p')
k = req_body.get('k')
temperture = req_body.get('temperture')
ph = req_body.get('ph')
humidity = req_body.get('humidity')
rainfall = req_body.get('rainfall')

if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
if n and p and k and temperture and ph and humidity and rainfall:
return func.HttpResponse(predict_fun(n, p, k, temperture, ph, humidity, rainfall))
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
)
10 changes: 10 additions & 0 deletions azure_functions/utils/predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import json
import azure.functions as func
import pickle

model = pickle.load(open('../crop_recommendation_model/finalizedresult.pkl', 'rb'))
output = -1
def predict_fun(n, p, k, temperture, ph, humidity, rainfall):
global output
output = model.predict([[n, p, k, temperture, ph, humidity, rainfall]])
return json.dumps(output.tolist())

0 comments on commit 062cc22

Please sign in to comment.