BasitAliii commited on
Commit
fd9459a
Β·
verified Β·
1 Parent(s): db3ea53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -19
app.py CHANGED
@@ -248,38 +248,52 @@ with right:
248
 
249
  try:
250
  sys_msg, user_msg = make_prompt_for_matching(
251
- current,
252
- profiles,
253
- 3
254
  )
255
  raw_matches = ask_groq_for_matches(sys_msg, user_msg)
 
256
  except Exception as e:
257
- st.info(f"Using local matching due to: {str(e)[:100]}...")
 
 
258
  raw_matches = calculate_local_matches(
259
  current,
260
  [p for p in profiles if p.id != current.id],
261
  3,
262
  )
263
 
264
- # Enrich returned matches (NO score)
265
  enriched = []
 
266
  for rm in raw_matches:
267
  prof = store.find_by_username(rm.get("username", ""))
268
- if prof:
269
- enriched.append({
270
- "username": prof.username,
271
- "offers": prof.offers,
272
- "wants": prof.wants,
273
- "avatar": prof.avatar,
274
- "reason": rm.get("reason", "AI Match")
275
- })
 
 
 
 
 
 
 
 
 
 
 
276
 
277
  st.session_state["matches"] = enriched
278
 
279
  matches_list = st.session_state.get("matches", [])
280
 
281
  if matches_list:
282
- st.markdown(f"### 🎯 Top {len(matches_list)} Matches for {pick}")
 
 
283
 
284
  for m in matches_list:
285
  st.markdown("<div class='card'>", unsafe_allow_html=True)
@@ -290,17 +304,34 @@ with right:
290
  if m.get("avatar") and Path(m["avatar"]).exists():
291
  st.image(m["avatar"], width=120)
292
  else:
293
- st.image("https://via.placeholder.com/120", width=120)
 
 
 
294
 
295
  with cols[1]:
296
- st.markdown(f"### {m.get('username')}")
297
- st.markdown(f"🧠 **Offers:** {', '.join(m.get('offers', [])) or 'β€”'}")
298
- st.markdown(f"🎯 **Wants:** {', '.join(m.get('wants', [])) or 'β€”'}")
299
- st.markdown(f"*{m.get('reason', 'AI Match')}*")
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  st.markdown("</div>", unsafe_allow_html=True)
302
 
303
 
 
304
  # ----------------------------------------------
305
  # Feedback
306
  # ----------------------------------------------
 
248
 
249
  try:
250
  sys_msg, user_msg = make_prompt_for_matching(
251
+ current, profiles, 3
 
 
252
  )
253
  raw_matches = ask_groq_for_matches(sys_msg, user_msg)
254
+
255
  except Exception as e:
256
+ st.info(
257
+ f"Using local matching due to: {str(e)[:100]}..."
258
+ )
259
  raw_matches = calculate_local_matches(
260
  current,
261
  [p for p in profiles if p.id != current.id],
262
  3,
263
  )
264
 
 
265
  enriched = []
266
+
267
  for rm in raw_matches:
268
  prof = store.find_by_username(rm.get("username", ""))
269
+ if not prof:
270
+ continue
271
+
272
+ # πŸ”’ SAFE SCORE HANDLING
273
+ try:
274
+ raw_score = float(rm.get("score", 0))
275
+ except (ValueError, TypeError):
276
+ raw_score = 0.0
277
+
278
+ raw_score = max(0.0, min(raw_score, 1.0))
279
+
280
+ enriched.append({
281
+ "username": prof.username,
282
+ "offers": prof.offers,
283
+ "wants": prof.wants,
284
+ "avatar": prof.avatar,
285
+ "score": raw_score, # ALWAYS 0–1
286
+ "reason": rm.get("reason", "AI Match")
287
+ })
288
 
289
  st.session_state["matches"] = enriched
290
 
291
  matches_list = st.session_state.get("matches", [])
292
 
293
  if matches_list:
294
+ st.markdown(
295
+ f"### 🎯 Top {len(matches_list)} Matches for {pick}"
296
+ )
297
 
298
  for m in matches_list:
299
  st.markdown("<div class='card'>", unsafe_allow_html=True)
 
304
  if m.get("avatar") and Path(m["avatar"]).exists():
305
  st.image(m["avatar"], width=120)
306
  else:
307
+ st.image(
308
+ "https://via.placeholder.com/120",
309
+ width=120
310
+ )
311
 
312
  with cols[1]:
313
+ st.markdown(f"### {m['username']}")
314
+
315
+ score_float = m["score"] # 0–1
316
+ score_percent = int(score_float * 100)
317
+
318
+ st.progress(score_float)
319
+ st.caption(f"Match Score: {score_percent}%")
320
+
321
+ st.markdown(
322
+ f"🧠 **Offers:** "
323
+ f"{', '.join(m['offers']) or 'β€”'}"
324
+ )
325
+ st.markdown(
326
+ f"🎯 **Wants:** "
327
+ f"{', '.join(m['wants']) or 'β€”'}"
328
+ )
329
+ st.markdown(f"*{m['reason']}*")
330
 
331
  st.markdown("</div>", unsafe_allow_html=True)
332
 
333
 
334
+
335
  # ----------------------------------------------
336
  # Feedback
337
  # ----------------------------------------------