rajkhanke commited on
Commit
b2fcb16
·
verified ·
1 Parent(s): c3f99d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -18,12 +18,10 @@ def validate_coordinates(lat, lon):
18
  except (TypeError, ValueError):
19
  return None, None
20
 
21
-
22
  @app.route('/')
23
  def index():
24
  return render_template('index.html')
25
 
26
-
27
  @app.route('/get_weather_data', methods=['GET'])
28
  def get_weather_data():
29
  """
@@ -48,7 +46,7 @@ def get_weather_data():
48
  "hourly": "relative_humidity_2m,soil_moisture_3_to_9cm,cloudcover,windspeed_10m",
49
  "timezone": "auto"
50
  }
51
- resp = requests.get(forecast_url, params=forecast_params)
52
  resp.raise_for_status()
53
  data = resp.json()
54
 
@@ -89,7 +87,6 @@ def get_weather_data():
89
  except Exception as e:
90
  return jsonify({"error": str(e)}), 500
91
 
92
-
93
  @app.route('/get_soil_properties', methods=['GET'])
94
  def get_soil_properties():
95
  """Fetch soil properties using SoilGrids API and map to user-friendly names."""
@@ -101,19 +98,18 @@ def get_soil_properties():
101
 
102
  try:
103
  prop_url = "https://rest.isric.org/soilgrids/v2.0/properties/query"
 
 
104
  prop_params = {
105
  "lon": str(lon),
106
  "lat": str(lat),
107
- "property": [
108
- "bdod", "cec", "cfvo", "clay", "nitrogen",
109
- "ocd", "phh2o", "sand", "silt",
110
- "soc", "wv0010", "wv0033", "wv1500"
111
- ],
112
  "depth": "5-15cm",
113
  "value": "mean"
114
  }
115
  headers = {"accept": "application/json"}
116
- response = requests.get(prop_url, params=prop_params, headers=headers)
 
117
  response.raise_for_status()
118
  prop_data = response.json()
119
 
@@ -205,7 +201,6 @@ Please provide the complete report in {language} language only.
205
  )
206
  return response.text
207
 
208
-
209
  @app.route('/predict', methods=['POST'])
210
  def predict():
211
  form_data = request.form.to_dict()
@@ -334,6 +329,5 @@ def predict():
334
  </html>"""
335
  return Response(html_output, mimetype="text/html")
336
 
337
-
338
  if __name__ == '__main__':
339
  app.run(debug=True)
 
18
  except (TypeError, ValueError):
19
  return None, None
20
 
 
21
  @app.route('/')
22
  def index():
23
  return render_template('index.html')
24
 
 
25
  @app.route('/get_weather_data', methods=['GET'])
26
  def get_weather_data():
27
  """
 
46
  "hourly": "relative_humidity_2m,soil_moisture_3_to_9cm,cloudcover,windspeed_10m",
47
  "timezone": "auto"
48
  }
49
+ resp = requests.get(forecast_url, params=forecast_params, timeout=10)
50
  resp.raise_for_status()
51
  data = resp.json()
52
 
 
87
  except Exception as e:
88
  return jsonify({"error": str(e)}), 500
89
 
 
90
  @app.route('/get_soil_properties', methods=['GET'])
91
  def get_soil_properties():
92
  """Fetch soil properties using SoilGrids API and map to user-friendly names."""
 
98
 
99
  try:
100
  prop_url = "https://rest.isric.org/soilgrids/v2.0/properties/query"
101
+ # It's often better to send the list of properties as a comma-separated string.
102
+ properties = "bdod,cec,cfvo,clay,nitrogen,ocd,phh2o,sand,silt,soc,wv0010,wv0033,wv1500"
103
  prop_params = {
104
  "lon": str(lon),
105
  "lat": str(lat),
106
+ "property": properties,
 
 
 
 
107
  "depth": "5-15cm",
108
  "value": "mean"
109
  }
110
  headers = {"accept": "application/json"}
111
+ # Add timeout to avoid hanging (10 seconds in this example)
112
+ response = requests.get(prop_url, params=prop_params, headers=headers, timeout=10)
113
  response.raise_for_status()
114
  prop_data = response.json()
115
 
 
201
  )
202
  return response.text
203
 
 
204
  @app.route('/predict', methods=['POST'])
205
  def predict():
206
  form_data = request.form.to_dict()
 
329
  </html>"""
330
  return Response(html_output, mimetype="text/html")
331
 
 
332
  if __name__ == '__main__':
333
  app.run(debug=True)