Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -245,116 +245,57 @@ with right:
|
|
| 245 |
if st.button("✨ Find Best Matches", key="find_matches_button"):
|
| 246 |
with st.spinner("Finding best matches..."):
|
| 247 |
current = store.find_by_username(pick)
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
if isinstance(score_value, str):
|
| 276 |
-
# Try to extract numeric value from string
|
| 277 |
-
import re
|
| 278 |
-
numbers = re.findall(r'\d+\.?\d*', score_value)
|
| 279 |
-
if numbers:
|
| 280 |
-
score_value = float(numbers[0])
|
| 281 |
-
else:
|
| 282 |
-
score_value = 50.0 # Default
|
| 283 |
-
else:
|
| 284 |
-
score_value = float(score_value)
|
| 285 |
-
|
| 286 |
-
# Ensure score is between 0-100
|
| 287 |
-
score_value = max(0, min(100, score_value))
|
| 288 |
-
|
| 289 |
-
enriched.append({
|
| 290 |
-
"username": prof.username,
|
| 291 |
-
"offers": prof.offers,
|
| 292 |
-
"wants": prof.wants,
|
| 293 |
-
"avatar": prof.avatar,
|
| 294 |
-
"score": score_value,
|
| 295 |
-
"reason": rm.get("reason", "AI Match")
|
| 296 |
-
})
|
| 297 |
-
|
| 298 |
-
# Sort by score (highest first)
|
| 299 |
-
enriched.sort(key=lambda x: x.get("score", 0), reverse=True)
|
| 300 |
-
|
| 301 |
-
st.session_state["matches"] = enriched
|
| 302 |
-
st.session_state["current_profile"] = pick
|
| 303 |
-
|
| 304 |
-
# Display matches
|
| 305 |
matches_list = st.session_state.get("matches", [])
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
if matches_list and current_profile:
|
| 309 |
-
st.markdown(f"### 🎯 Top {len(matches_list)} Matches for {current_profile}")
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
# Progress bar with color based on score
|
| 332 |
-
if score >= 80:
|
| 333 |
-
progress_color = "green"
|
| 334 |
-
elif score >= 60:
|
| 335 |
-
progress_color = "blue"
|
| 336 |
-
elif score >= 40:
|
| 337 |
-
progress_color = "orange"
|
| 338 |
-
else:
|
| 339 |
-
progress_color = "red"
|
| 340 |
-
|
| 341 |
-
# Create a custom progress bar with HTML/CSS
|
| 342 |
-
progress_html = f"""
|
| 343 |
-
<div style="width: 100%; background-color: #f0f0f0; border-radius: 10px; margin: 5px 0;">
|
| 344 |
-
<div style="width: {score}%; background-color: {progress_color}; height: 10px; border-radius: 10px;"></div>
|
| 345 |
-
</div>
|
| 346 |
-
"""
|
| 347 |
-
st.markdown(progress_html, unsafe_allow_html=True)
|
| 348 |
-
|
| 349 |
-
st.markdown(f"🧠 **Offers:** {', '.join(m.get('offers', [])) or '—'}")
|
| 350 |
-
st.markdown(f"🎯 **Wants:** {', '.join(m.get('wants', [])) or '—'}")
|
| 351 |
-
st.markdown(f"*{m.get('reason', 'AI Match')}*")
|
| 352 |
-
|
| 353 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 354 |
-
|
| 355 |
-
# Add some spacing between matches
|
| 356 |
-
if idx < len(matches_list) - 1:
|
| 357 |
-
st.markdown("<br>", unsafe_allow_html=True)
|
| 358 |
|
| 359 |
# ----------------------------------------------
|
| 360 |
# Feedback
|
|
|
|
| 245 |
if st.button("✨ Find Best Matches", key="find_matches_button"):
|
| 246 |
with st.spinner("Finding best matches..."):
|
| 247 |
current = store.find_by_username(pick)
|
| 248 |
+
|
| 249 |
+
try:
|
| 250 |
+
sys_msg, user_msg = make_prompt_for_matching(current, profiles, 3)
|
| 251 |
+
raw_matches = ask_groq_for_matches(sys_msg, user_msg)
|
| 252 |
+
except Exception as e:
|
| 253 |
+
st.info(f"Using local matching due to: {str(e)[:100]}...")
|
| 254 |
+
raw_matches = calculate_local_matches(
|
| 255 |
+
current,
|
| 256 |
+
[p for p in profiles if p.id != current.id],
|
| 257 |
+
3,
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
# Enrich returned matches
|
| 261 |
+
enriched = []
|
| 262 |
+
for rm in raw_matches:
|
| 263 |
+
prof = store.find_by_username(rm.get("username", ""))
|
| 264 |
+
if prof:
|
| 265 |
+
enriched.append({
|
| 266 |
+
"username": prof.username,
|
| 267 |
+
"offers": prof.offers,
|
| 268 |
+
"wants": prof.wants,
|
| 269 |
+
"avatar": prof.avatar,
|
| 270 |
+
"score": int(float(rm.get("score", 0)) * 100),
|
| 271 |
+
"reason": rm.get("reason", "AI Match")
|
| 272 |
+
})
|
| 273 |
+
st.session_state["matches"] = enriched
|
| 274 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
matches_list = st.session_state.get("matches", [])
|
| 276 |
+
if matches_list:
|
| 277 |
+
st.markdown(f"### 🎯 Top {len(matches_list)} Matches for {pick}")
|
|
|
|
|
|
|
| 278 |
|
| 279 |
+
for m in matches_list:
|
| 280 |
+
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 281 |
+
cols = st.columns([1, 4])
|
| 282 |
+
|
| 283 |
+
with cols[0]:
|
| 284 |
+
if m.get("avatar") and Path(m["avatar"]).exists():
|
| 285 |
+
st.image(m["avatar"], width=120)
|
| 286 |
+
else:
|
| 287 |
+
st.image("https://via.placeholder.com/120", width=120)
|
| 288 |
+
|
| 289 |
+
with cols[1]:
|
| 290 |
+
st.markdown(f"### {m.get('username')}")
|
| 291 |
+
score = m.get('score', 0)
|
| 292 |
+
st.progress(score / 100)
|
| 293 |
+
st.caption(f"Match Score: {score}%")
|
| 294 |
+
st.markdown(f"🧠 **Offers:** {', '.join(m.get('offers', [])) or '—'}")
|
| 295 |
+
st.markdown(f"🎯 **Wants:** {', '.join(m.get('wants', [])) or '—'}")
|
| 296 |
+
st.markdown(f"*{m.get('reason', 'AI Match')}*")
|
| 297 |
+
|
| 298 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
# ----------------------------------------------
|
| 301 |
# Feedback
|