Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,6 @@ store = ProfileStore()
|
|
| 34 |
col_logo, col_title = st.columns([1, 6])
|
| 35 |
with col_logo:
|
| 36 |
try:
|
| 37 |
-
# Use uploaded logo if available
|
| 38 |
st.image("logo.jpg", width=90)
|
| 39 |
except:
|
| 40 |
st.image("https://via.placeholder.com/100x100/4F46E5/FFFFFF?text=π€", width=90)
|
|
@@ -102,19 +101,19 @@ with st.sidebar:
|
|
| 102 |
key="avatar_uploader"
|
| 103 |
)
|
| 104 |
|
| 105 |
-
#
|
| 106 |
if avatar_file:
|
| 107 |
st.image(avatar_file, width=150, caption="Preview Avatar")
|
| 108 |
-
if avatar_file.size > 800 * 1024:
|
| 109 |
st.error("File exceeds 800KB!")
|
| 110 |
avatar_file = None
|
| 111 |
|
| 112 |
st.markdown("---")
|
| 113 |
col_create, col_update = st.columns(2)
|
| 114 |
|
| 115 |
-
#
|
| 116 |
with col_create:
|
| 117 |
-
if st.button("β Create", key="create_button"):
|
| 118 |
if not username.strip():
|
| 119 |
st.error("Username is required!")
|
| 120 |
elif store.find_by_username(username):
|
|
@@ -151,13 +150,13 @@ with st.sidebar:
|
|
| 151 |
del st.session_state["avatar_uploader"]
|
| 152 |
# Clear previous matches
|
| 153 |
st.session_state["matches"] = []
|
| 154 |
-
st.
|
| 155 |
else:
|
| 156 |
st.error(msg)
|
| 157 |
|
| 158 |
-
#
|
| 159 |
with col_update:
|
| 160 |
-
if st.button("πΎ Update", key="update_button"):
|
| 161 |
existing = store.find_by_username(username)
|
| 162 |
if not existing:
|
| 163 |
st.error("Profile does not exist.")
|
|
@@ -181,11 +180,11 @@ with st.sidebar:
|
|
| 181 |
st.success("Profile updated")
|
| 182 |
if "avatar_uploader" in st.session_state:
|
| 183 |
del st.session_state["avatar_uploader"]
|
| 184 |
-
st.
|
| 185 |
|
| 186 |
-
#
|
| 187 |
if selected_user != "β Create New β":
|
| 188 |
-
if st.button("ποΈ Delete Profile", key="delete_button"):
|
| 189 |
ok, msg = store.delete(selected_user)
|
| 190 |
if ok:
|
| 191 |
st.warning(msg)
|
|
@@ -195,7 +194,7 @@ with st.sidebar:
|
|
| 195 |
del st.session_state[key]
|
| 196 |
if "avatar_uploader" in st.session_state:
|
| 197 |
del st.session_state["avatar_uploader"]
|
| 198 |
-
st.
|
| 199 |
else:
|
| 200 |
st.error(msg)
|
| 201 |
|
|
@@ -229,7 +228,7 @@ with left:
|
|
| 229 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 230 |
|
| 231 |
# ----------------------------------------------
|
| 232 |
-
# AI Matchmaking
|
| 233 |
# ----------------------------------------------
|
| 234 |
with right:
|
| 235 |
st.subheader("π€ AI Matchmaking")
|
|
@@ -244,34 +243,39 @@ with right:
|
|
| 244 |
)
|
| 245 |
|
| 246 |
if st.button("β¨ Find Best Matches", key="find_matches_button"):
|
| 247 |
-
|
| 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 |
matches_list = st.session_state.get("matches", [])
|
|
|
|
|
|
|
|
|
|
| 275 |
for m in matches_list:
|
| 276 |
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 277 |
cols = st.columns([1, 4])
|
|
@@ -284,10 +288,12 @@ with right:
|
|
| 284 |
|
| 285 |
with cols[1]:
|
| 286 |
st.markdown(f"### {m.get('username')}")
|
|
|
|
|
|
|
|
|
|
| 287 |
st.markdown(f"π§ **Offers:** {', '.join(m.get('offers', [])) or 'β'}")
|
| 288 |
st.markdown(f"π― **Wants:** {', '.join(m.get('wants', [])) or 'β'}")
|
| 289 |
-
st.markdown(f"
|
| 290 |
-
st.markdown(f"**Reason:** {m.get('reason', '')}")
|
| 291 |
|
| 292 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 293 |
|
|
@@ -308,6 +314,6 @@ with st.sidebar:
|
|
| 308 |
st.success("Thank you!")
|
| 309 |
if "feedback_text" in st.session_state:
|
| 310 |
del st.session_state["feedback_text"]
|
| 311 |
-
st.
|
| 312 |
else:
|
| 313 |
-
st.warning("Please write feedback.")
|
|
|
|
| 34 |
col_logo, col_title = st.columns([1, 6])
|
| 35 |
with col_logo:
|
| 36 |
try:
|
|
|
|
| 37 |
st.image("logo.jpg", width=90)
|
| 38 |
except:
|
| 39 |
st.image("https://via.placeholder.com/100x100/4F46E5/FFFFFF?text=π€", width=90)
|
|
|
|
| 101 |
key="avatar_uploader"
|
| 102 |
)
|
| 103 |
|
| 104 |
+
# Avatar Preview & Size Check
|
| 105 |
if avatar_file:
|
| 106 |
st.image(avatar_file, width=150, caption="Preview Avatar")
|
| 107 |
+
if avatar_file.size > 800 * 1024:
|
| 108 |
st.error("File exceeds 800KB!")
|
| 109 |
avatar_file = None
|
| 110 |
|
| 111 |
st.markdown("---")
|
| 112 |
col_create, col_update = st.columns(2)
|
| 113 |
|
| 114 |
+
# Create Button
|
| 115 |
with col_create:
|
| 116 |
+
if st.button("β Create", key="create_button", use_container_width=True):
|
| 117 |
if not username.strip():
|
| 118 |
st.error("Username is required!")
|
| 119 |
elif store.find_by_username(username):
|
|
|
|
| 150 |
del st.session_state["avatar_uploader"]
|
| 151 |
# Clear previous matches
|
| 152 |
st.session_state["matches"] = []
|
| 153 |
+
st.rerun()
|
| 154 |
else:
|
| 155 |
st.error(msg)
|
| 156 |
|
| 157 |
+
# Update Button
|
| 158 |
with col_update:
|
| 159 |
+
if st.button("πΎ Update", key="update_button", use_container_width=True):
|
| 160 |
existing = store.find_by_username(username)
|
| 161 |
if not existing:
|
| 162 |
st.error("Profile does not exist.")
|
|
|
|
| 180 |
st.success("Profile updated")
|
| 181 |
if "avatar_uploader" in st.session_state:
|
| 182 |
del st.session_state["avatar_uploader"]
|
| 183 |
+
st.rerun()
|
| 184 |
|
| 185 |
+
# Delete Button
|
| 186 |
if selected_user != "β Create New β":
|
| 187 |
+
if st.button("ποΈ Delete Profile", key="delete_button", type="secondary"):
|
| 188 |
ok, msg = store.delete(selected_user)
|
| 189 |
if ok:
|
| 190 |
st.warning(msg)
|
|
|
|
| 194 |
del st.session_state[key]
|
| 195 |
if "avatar_uploader" in st.session_state:
|
| 196 |
del st.session_state["avatar_uploader"]
|
| 197 |
+
st.rerun()
|
| 198 |
else:
|
| 199 |
st.error(msg)
|
| 200 |
|
|
|
|
| 228 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 229 |
|
| 230 |
# ----------------------------------------------
|
| 231 |
+
# AI Matchmaking
|
| 232 |
# ----------------------------------------------
|
| 233 |
with right:
|
| 234 |
st.subheader("π€ AI Matchmaking")
|
|
|
|
| 243 |
)
|
| 244 |
|
| 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])
|
|
|
|
| 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 |
|
|
|
|
| 314 |
st.success("Thank you!")
|
| 315 |
if "feedback_text" in st.session_state:
|
| 316 |
del st.session_state["feedback_text"]
|
| 317 |
+
st.rerun()
|
| 318 |
else:
|
| 319 |
+
st.warning("Please write feedback.")
|