BasitAliii commited on
Commit
b25cdde
Β·
verified Β·
1 Parent(s): abfe3d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -59
app.py CHANGED
@@ -30,7 +30,7 @@ store = ProfileStore()
30
  col_logo, col_title = st.columns([1, 6])
31
  with col_logo:
32
  try:
33
- st.image("logo.jpg", width=90) # Use uploaded logo
34
  except:
35
  st.image(
36
  "https://via.placeholder.com/100x100/4F46E5/FFFFFF?text=🀝",
@@ -99,7 +99,7 @@ with st.sidebar:
99
  # ---------- Avatar Preview ----------
100
  if avatar_file:
101
  st.image(avatar_file, width=150, caption="Preview of avatar")
102
- if avatar_file.size > 800 * 1024: # 800KB limit
103
  st.error("File exceeds maximum size of 800KB!")
104
  avatar_file = None
105
 
@@ -143,6 +143,8 @@ with st.sidebar:
143
  del st.session_state[key]
144
  if "avatar_uploader" in st.session_state:
145
  del st.session_state["avatar_uploader"]
 
 
146
  st.rerun()
147
  else:
148
  st.error(msg)
@@ -173,23 +175,10 @@ with st.sidebar:
173
  st.success("Profile updated")
174
  if "avatar_uploader" in st.session_state:
175
  del st.session_state["avatar_uploader"]
 
 
176
  st.rerun()
177
 
178
- # ---------- DELETE PROFILE ----------
179
- if selected_user != "β€” Create New β€”":
180
- if st.button("πŸ—‘οΈ Delete Profile", type="secondary", key="delete_button"):
181
- ok, msg = store.delete(selected_user)
182
- if ok:
183
- st.warning(msg)
184
- for key in ["offers_text", "wants_text", "availability", "preferences"]:
185
- if key in st.session_state:
186
- del st.session_state[key]
187
- if "avatar_uploader" in st.session_state:
188
- del st.session_state["avatar_uploader"]
189
- st.rerun()
190
- else:
191
- st.error(msg)
192
-
193
  # ---------- MAIN CONTENT ----------
194
  left, right = st.columns([2, 3])
195
 
@@ -221,7 +210,6 @@ with left:
221
  st.markdown(f"🎯 **Wants:** {', '.join(p.wants) or 'β€”'}")
222
  st.markdown("</div>", unsafe_allow_html=True)
223
 
224
- # ---------- AI MATCHMAKING ----------
225
  # ---------- AI MATCHMAKING ----------
226
  with right:
227
  st.subheader("πŸ€– AI Matchmaking")
@@ -236,48 +224,40 @@ with right:
236
  )
237
 
238
  if st.button("✨ Find Best Matches", key="find_matches_button"):
239
- with st.spinner("Analyzing profiles..."):
240
- current = store.find_by_username(pick)
241
-
242
- try:
243
- sys_msg, user_msg = make_prompt_for_matching(current, profiles, 3)
244
- matches = ask_groq_for_matches(sys_msg, user_msg)
245
- except Exception:
246
- matches = calculate_local_matches(
247
- current,
248
- [p for p in profiles if p.id != current.id],
249
- 3,
250
- )
251
-
252
- if not matches:
253
- st.info("No matches found.")
254
- else:
255
- st.markdown("<div class='matches-container'>", unsafe_allow_html=True)
256
-
257
- for m in matches:
258
- score_percent = int(float(m.get("score", 0)) * 100) # Convert 0-1 to 0-100%
259
- st.markdown("<div class='card'>", unsafe_allow_html=True)
260
- cols = st.columns([1, 3])
261
-
262
- with cols[0]:
263
- avatar_path = m.get("avatar")
264
- if avatar_path and Path(avatar_path).exists():
265
- st.image(avatar_path, width=80)
266
- else:
267
- st.image("https://via.placeholder.com/80", width=80)
268
-
269
- with cols[1]:
270
- st.markdown(f"### {m.get('username', 'Unknown')}")
271
- st.markdown(f"🧠 Offers: {', '.join(m.get('offers', [])) or 'β€”'}")
272
- st.markdown(f"🎯 Wants: {', '.join(m.get('wants', [])) or 'β€”'}")
273
- st.markdown(f"⏰ {m.get('availability', 'N/A')} β€’ πŸ—£ {m.get('preferences', 'β€”')}")
274
- st.markdown(f"**Match Score:** {score_percent}%")
275
- st.caption(m.get("reason", "AI Match"))
276
-
277
- st.markdown("</div>", unsafe_allow_html=True)
278
-
279
- st.markdown("</div>", unsafe_allow_html=True)
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
 
282
  # ---------- FEEDBACK ----------
283
  with st.sidebar:
 
30
  col_logo, col_title = st.columns([1, 6])
31
  with col_logo:
32
  try:
33
+ st.image("logo.jpg", width=90) # Uploaded logo
34
  except:
35
  st.image(
36
  "https://via.placeholder.com/100x100/4F46E5/FFFFFF?text=🀝",
 
99
  # ---------- Avatar Preview ----------
100
  if avatar_file:
101
  st.image(avatar_file, width=150, caption="Preview of avatar")
102
+ if avatar_file.size > 800 * 1024:
103
  st.error("File exceeds maximum size of 800KB!")
104
  avatar_file = None
105
 
 
143
  del st.session_state[key]
144
  if "avatar_uploader" in st.session_state:
145
  del st.session_state["avatar_uploader"]
146
+ # Clear previous matches
147
+ st.session_state["matches"] = []
148
  st.rerun()
149
  else:
150
  st.error(msg)
 
175
  st.success("Profile updated")
176
  if "avatar_uploader" in st.session_state:
177
  del st.session_state["avatar_uploader"]
178
+ # Clear previous matches
179
+ st.session_state["matches"] = []
180
  st.rerun()
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  # ---------- MAIN CONTENT ----------
183
  left, right = st.columns([2, 3])
184
 
 
210
  st.markdown(f"🎯 **Wants:** {', '.join(p.wants) or 'β€”'}")
211
  st.markdown("</div>", unsafe_allow_html=True)
212
 
 
213
  # ---------- AI MATCHMAKING ----------
214
  with right:
215
  st.subheader("πŸ€– AI Matchmaking")
 
224
  )
225
 
226
  if st.button("✨ Find Best Matches", key="find_matches_button"):
227
+ current = store.find_by_username(pick)
228
+ try:
229
+ sys_msg, user_msg = make_prompt_for_matching(current, profiles, 3)
230
+ matches = ask_groq_for_matches(sys_msg, user_msg)
231
+ except Exception:
232
+ matches = calculate_local_matches(
233
+ current,
234
+ [p for p in profiles if p.id != current.id],
235
+ 3,
236
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
+ # Save matches in session state to persist
239
+ st.session_state["matches"] = matches
240
+
241
+ # Display matches from session state
242
+ matches_to_show = st.session_state.get("matches", [])
243
+ if matches_to_show:
244
+ for m in matches_to_show:
245
+ st.markdown("<div class='card'>", unsafe_allow_html=True)
246
+ cols = st.columns([1, 4])
247
+
248
+ with cols[0]:
249
+ avatar_path = m.get("avatar")
250
+ if avatar_path and Path(avatar_path).exists():
251
+ st.image(avatar_path, width=120)
252
+ else:
253
+ st.image("https://via.placeholder.com/120", width=120)
254
+
255
+ with cols[1]:
256
+ st.markdown(f"### {m.get('username')}")
257
+ st.caption(f"🧠 Offers: {', '.join(m.get('offers', []))}")
258
+ st.caption(f"🎯 Wants: {', '.join(m.get('wants', []))}")
259
+ st.caption(f"Match Reason: {m.get('reason', 'AI Match')}")
260
+ st.markdown("</div>", unsafe_allow_html=True)
261
 
262
  # ---------- FEEDBACK ----------
263
  with st.sidebar: