Infinity-1995 commited on
Commit
6a74830
·
verified ·
1 Parent(s): f47e767

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -26,6 +26,7 @@ def haversine(lat1, lon1, lat2, lon2):
26
  R = 6371
27
  dlat = math.radians(lat2-lat1)
28
  dlon = math.radians(lon2-lon1)
 
29
  a = math.sin(dlat/2)**2 + math.cos(math.radians(lat1))*math.cos(math.radians(lat2))*math.sin(dlon/2)**2
30
  return R * (2 * math.atan2(math.sqrt(a), math.sqrt(1-a)))
31
 
@@ -65,9 +66,7 @@ def score(meals, ngo, foodType, expiry, lat, lon):
65
  elif expiry <= 24:
66
  urgency += 15
67
 
68
- learning = ngo_learning[ngo["name"]]
69
-
70
- return round(dist_score*0.2 + cap_score*0.2 + urgency*0.55 + learning, 2)
71
 
72
  def explain(ngo, meals, foodType, score, rank):
73
 
@@ -78,8 +77,7 @@ Food: {foodType}
78
  Meals: {meals}
79
  Score: {score}
80
 
81
- Explain in 1–2 lines why this NGO is selected.
82
- Make each explanation different.
83
  """
84
 
85
  try:
@@ -89,12 +87,13 @@ Make each explanation different.
89
  temperature=0.8
90
  ).strip()
91
  except:
92
- return "Matched based on urgency and compatibility."
93
 
94
  @app.route("/analyze", methods=["POST"])
95
  def analyze():
96
 
97
  data = request.json
 
98
  meals = int(data["meals"])
99
  foodType = data["foodType"]
100
  expiry = data["expiry"]
@@ -104,6 +103,7 @@ def analyze():
104
  results = []
105
 
106
  for ngo in NGOS:
 
107
  s = score(meals, ngo, foodType, expiry, lat, lon)
108
 
109
  results.append({
@@ -116,6 +116,7 @@ def analyze():
116
  results.sort(key=lambda x: x["score"], reverse=True)
117
 
118
  for i, r in enumerate(results):
 
119
  ngo_obj = next(n for n in NGOS if n["name"] == r["recipient"])
120
 
121
  r["priority"] = (
@@ -130,7 +131,7 @@ def analyze():
130
 
131
  @app.route("/")
132
  def home():
133
- return "NourishNet Running"
134
 
135
  if __name__ == "__main__":
136
  app.run(host="0.0.0.0", port=7860)
 
26
  R = 6371
27
  dlat = math.radians(lat2-lat1)
28
  dlon = math.radians(lon2-lon1)
29
+
30
  a = math.sin(dlat/2)**2 + math.cos(math.radians(lat1))*math.cos(math.radians(lat2))*math.sin(dlon/2)**2
31
  return R * (2 * math.atan2(math.sqrt(a), math.sqrt(1-a)))
32
 
 
66
  elif expiry <= 24:
67
  urgency += 15
68
 
69
+ return round(dist_score*0.2 + cap_score*0.2 + urgency*0.55 + ngo_learning[ngo["name"]], 2)
 
 
70
 
71
  def explain(ngo, meals, foodType, score, rank):
72
 
 
77
  Meals: {meals}
78
  Score: {score}
79
 
80
+ Give 1–2 line unique explanation. No repetition.
 
81
  """
82
 
83
  try:
 
87
  temperature=0.8
88
  ).strip()
89
  except:
90
+ return "Matched based on urgency and suitability."
91
 
92
  @app.route("/analyze", methods=["POST"])
93
  def analyze():
94
 
95
  data = request.json
96
+
97
  meals = int(data["meals"])
98
  foodType = data["foodType"]
99
  expiry = data["expiry"]
 
103
  results = []
104
 
105
  for ngo in NGOS:
106
+
107
  s = score(meals, ngo, foodType, expiry, lat, lon)
108
 
109
  results.append({
 
116
  results.sort(key=lambda x: x["score"], reverse=True)
117
 
118
  for i, r in enumerate(results):
119
+
120
  ngo_obj = next(n for n in NGOS if n["name"] == r["recipient"])
121
 
122
  r["priority"] = (
 
131
 
132
  @app.route("/")
133
  def home():
134
+ return "NourishNet AI Running 🚀"
135
 
136
  if __name__ == "__main__":
137
  app.run(host="0.0.0.0", port=7860)