BasitAliii commited on
Commit
bb2d1c0
Β·
verified Β·
1 Parent(s): 7b64bbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -42
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
- # ---------- Avatar Preview & Size Check
106
  if avatar_file:
107
  st.image(avatar_file, width=150, caption="Preview Avatar")
108
- if avatar_file.size > 800 * 1024: # 800KB limit
109
  st.error("File exceeds 800KB!")
110
  avatar_file = None
111
 
112
  st.markdown("---")
113
  col_create, col_update = st.columns(2)
114
 
115
- # ---------- Create Button
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.experimental_rerun()
155
  else:
156
  st.error(msg)
157
 
158
- # ---------- Update Button
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.experimental_rerun()
185
 
186
- # ---------- Delete Button
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.experimental_rerun()
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 (Profile Cards)
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
- 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:
253
- raw_matches = calculate_local_matches(
254
- current,
255
- [p for p in profiles if p.id != current.id],
256
- 3,
257
- )
 
 
258
 
259
- # Enrich returned matches
260
- enriched = []
261
- for rm in raw_matches:
262
- prof = store.find_by_username(rm.get("username", ""))
263
- if prof:
264
- enriched.append({
265
- "username": prof.username,
266
- "offers": prof.offers,
267
- "wants": prof.wants,
268
- "avatar": prof.avatar,
269
- "score": int(float(rm.get("score", 0)) * 100),
270
- "reason": rm.get("reason", "AI Match")
271
- })
272
- st.session_state["matches"] = enriched
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"**Match Score:** {m.get('score', 0)}%")
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.experimental_rerun()
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.")