Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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) #
|
| 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:
|
| 103 |
st.error("File exceeds maximum size of 800KB!")
|
| 104 |
avatar_file = None
|
| 105 |
|
|
@@ -137,15 +137,13 @@ with st.sidebar:
|
|
| 137 |
ok, msg = store.add_or_update(profile)
|
| 138 |
if ok:
|
| 139 |
st.success(msg)
|
| 140 |
-
# Clear
|
| 141 |
-
for key in ["offers_text", "wants_text", "availability", "preferences"]:
|
| 142 |
if key in st.session_state:
|
| 143 |
del st.session_state[key]
|
| 144 |
if "avatar_uploader" in st.session_state:
|
| 145 |
del st.session_state["avatar_uploader"]
|
| 146 |
-
|
| 147 |
-
st.session_state["matches"] = []
|
| 148 |
-
st.rerun()
|
| 149 |
else:
|
| 150 |
st.error(msg)
|
| 151 |
|
|
@@ -175,9 +173,25 @@ with st.sidebar:
|
|
| 175 |
st.success("Profile updated")
|
| 176 |
if "avatar_uploader" in st.session_state:
|
| 177 |
del st.session_state["avatar_uploader"]
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
# ---------- MAIN CONTENT ----------
|
| 183 |
left, right = st.columns([2, 3])
|
|
@@ -224,40 +238,54 @@ with right:
|
|
| 224 |
)
|
| 225 |
|
| 226 |
if st.button("β¨ Find Best Matches", key="find_matches_button"):
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
st.
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
# ---------- FEEDBACK ----------
|
| 263 |
with st.sidebar:
|
|
@@ -276,6 +304,6 @@ with st.sidebar:
|
|
| 276 |
st.success("Thank you!")
|
| 277 |
if "feedback_text" in st.session_state:
|
| 278 |
del st.session_state["feedback_text"]
|
| 279 |
-
st.
|
| 280 |
else:
|
| 281 |
st.warning("Please write feedback.")
|
|
|
|
| 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 |
# ---------- 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 max
|
| 103 |
st.error("File exceeds maximum size of 800KB!")
|
| 104 |
avatar_file = None
|
| 105 |
|
|
|
|
| 137 |
ok, msg = store.add_or_update(profile)
|
| 138 |
if ok:
|
| 139 |
st.success(msg)
|
| 140 |
+
# Clear fields
|
| 141 |
+
for key in ["offers_text", "wants_text", "availability", "preferences", "username_input"]:
|
| 142 |
if key in st.session_state:
|
| 143 |
del st.session_state[key]
|
| 144 |
if "avatar_uploader" in st.session_state:
|
| 145 |
del st.session_state["avatar_uploader"]
|
| 146 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
| 147 |
else:
|
| 148 |
st.error(msg)
|
| 149 |
|
|
|
|
| 173 |
st.success("Profile updated")
|
| 174 |
if "avatar_uploader" in st.session_state:
|
| 175 |
del st.session_state["avatar_uploader"]
|
| 176 |
+
st.experimental_rerun()
|
| 177 |
+
|
| 178 |
+
# ---------- DELETE PROFILE ----------
|
| 179 |
+
if selected_user != "β Create New β":
|
| 180 |
+
if st.button("ποΈ Delete Profile", type="secondary", key="delete_button"):
|
| 181 |
+
profiles = store.load_all()
|
| 182 |
+
profile_to_delete = next((p for p in profiles if p.username == selected_user), None)
|
| 183 |
+
if profile_to_delete:
|
| 184 |
+
profiles.remove(profile_to_delete)
|
| 185 |
+
store.save_all(profiles)
|
| 186 |
+
st.warning(f"Profile '{selected_user}' deleted")
|
| 187 |
+
for key in ["offers_text", "wants_text", "availability", "preferences", "username_input"]:
|
| 188 |
+
if key in st.session_state:
|
| 189 |
+
del st.session_state[key]
|
| 190 |
+
if "avatar_uploader" in st.session_state:
|
| 191 |
+
del st.session_state["avatar_uploader"]
|
| 192 |
+
st.experimental_rerun()
|
| 193 |
+
else:
|
| 194 |
+
st.error("Profile not found")
|
| 195 |
|
| 196 |
# ---------- MAIN CONTENT ----------
|
| 197 |
left, right = st.columns([2, 3])
|
|
|
|
| 238 |
)
|
| 239 |
|
| 240 |
if st.button("β¨ Find Best Matches", key="find_matches_button"):
|
| 241 |
+
with st.spinner("Analyzing profiles..."):
|
| 242 |
+
current = store.find_by_username(pick)
|
| 243 |
+
matches = []
|
| 244 |
+
|
| 245 |
+
try:
|
| 246 |
+
sys_msg, user_msg = make_prompt_for_matching(current, profiles, 3)
|
| 247 |
+
raw_matches = ask_groq_for_matches(sys_msg, user_msg)
|
| 248 |
+
# Enrich Groq matches with full profile info
|
| 249 |
+
for rm in raw_matches:
|
| 250 |
+
profile = store.find_by_username(rm.get("username", ""))
|
| 251 |
+
if profile:
|
| 252 |
+
matches.append({
|
| 253 |
+
"username": profile.username,
|
| 254 |
+
"offers": profile.offers,
|
| 255 |
+
"wants": profile.wants,
|
| 256 |
+
"avatar": profile.avatar,
|
| 257 |
+
"score": int(float(rm.get("score", 0)) * 100),
|
| 258 |
+
"reason": rm.get("reason", "AI Match")
|
| 259 |
+
})
|
| 260 |
+
except Exception:
|
| 261 |
+
matches = calculate_local_matches(
|
| 262 |
+
current,
|
| 263 |
+
[p for p in profiles if p.id != current.id],
|
| 264 |
+
3,
|
| 265 |
+
)
|
| 266 |
+
# Convert score 0-1 to 0-100%
|
| 267 |
+
for m in matches:
|
| 268 |
+
m["score"] = int(m["score"] * 100)
|
| 269 |
+
|
| 270 |
+
# Display matches
|
| 271 |
+
for m in matches:
|
| 272 |
+
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 273 |
+
cols = st.columns([1, 4])
|
| 274 |
+
with cols[0]:
|
| 275 |
+
if m.get("avatar") and Path(m["avatar"]).exists():
|
| 276 |
+
st.image(m["avatar"], width=100)
|
| 277 |
+
else:
|
| 278 |
+
st.image(
|
| 279 |
+
"https://via.placeholder.com/100",
|
| 280 |
+
width=100
|
| 281 |
+
)
|
| 282 |
+
with cols[1]:
|
| 283 |
+
st.markdown(f"### {m.get('username')}")
|
| 284 |
+
st.markdown(f"π§ **Offers:** {', '.join(m.get('offers', [])) or 'β'}")
|
| 285 |
+
st.markdown(f"π― **Wants:** {', '.join(m.get('wants', [])) or 'β'}")
|
| 286 |
+
st.markdown(f"**Match Score:** {m.get('score', 0)}%")
|
| 287 |
+
st.markdown(f"Match Reason: {m.get('reason', 'AI Match')}")
|
| 288 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 289 |
|
| 290 |
# ---------- FEEDBACK ----------
|
| 291 |
with st.sidebar:
|
|
|
|
| 304 |
st.success("Thank you!")
|
| 305 |
if "feedback_text" in st.session_state:
|
| 306 |
del st.session_state["feedback_text"]
|
| 307 |
+
st.experimental_rerun()
|
| 308 |
else:
|
| 309 |
st.warning("Please write feedback.")
|