Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Piexie3 committed Sep 24, 2023
1 parent ee65988 commit 0c95bde
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions disease_detection/crop_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
import requests

def crop_prediction(msg_received):
# try:
N = int(msg_received['nitrogen'])
P = int(msg_received['phosphorous'])
K = int(msg_received['pottasium'])
ph = float(msg_received['ph'])
rainfall = float(msg_received['rainfall'])
try:
N = int(msg_received['nitrogen'])
P = int(msg_received['phosphorous'])
K = int(msg_received['pottasium'])
ph = float(msg_received['ph'])
rainfall = float(msg_received['rainfall'])

# state = request.form.get("stt")
city = msg_received['city']
# state = request.form.get("stt")
city = msg_received['city']

if city != None:
temperature, humidity = weather_fetch(msg_received)
data = np.array([[N, P, K, temperature, humidity, ph, rainfall]])
my_prediction = crop_recommendation_model.predict(data)
final_prediction = my_prediction[0]
if city != None:
temperature, humidity = weather_fetch(msg_received)
data = np.array([[N, P, K, temperature, humidity, ph, rainfall]])
my_prediction = crop_recommendation_model.predict(data)
final_prediction = my_prediction[0]

return final_prediction
return final_prediction

else :
else :
return {
"code": -1,
"msg": "Unknown Error please try again",
}
except Exception as e:
return {
"code": -1,
"msg": "Unknown Error please try again",
"msg": str(e),
}
# except Exception as e:
# return {
# "code": -1,
# "msg": str(e),
# }


def weather_fetch(msg_received):
Expand All @@ -54,6 +54,7 @@ def weather_fetch(msg_received):

if x["cod"] != "404":
y = x["main"]
print(y)
temperature = round((y["temp"] - 273.15), 2)
humidity = y["humidity"]
return temperature, humidity
Expand Down

0 comments on commit 0c95bde

Please sign in to comment.