Timo commited on
Commit
d885b74
·
1 Parent(s): 6dadf8f

Does this fix duplicates

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +96 -94
src/streamlit_app.py CHANGED
@@ -201,107 +201,109 @@ def undo_last():
201
 
202
 
203
  # --- Tab 1: Draft -------------------------------------------------------
 
204
  with tabs[0]:
205
- if st.session_state.get("set_code") == "EOE":
206
- st.warning("The model is not trained for this set. Results may be inaccurate.", icon="⚠️")
207
-
208
- if st.session_state["undo_stack"]:
209
- st.button("↩️ Undo last action", on_click=undo_last)
210
-
211
- scores = {}
212
- pick = None
213
-
214
- if st.session_state["pack"]:
215
- pack = st.session_state["pack"]
216
- deck = st.session_state["deck"]
217
-
218
- try:
219
- pick, logits, scores = rank_cards(deck, pack)
220
- if pick:
221
- st.success(f"💡 Suggested pick: **{pick}**", icon="✨")
222
- except Exception as e:
223
- st.error(f"Error calculating card rankings: {e}")
224
-
225
- options = list(model.cards[set_code.lower()].keys())
226
- c1, c2 = st.columns(2)
227
- with c1:
228
- st.subheader("Add to Deck")
229
- deck_sel = st.selectbox(
230
- "Search card (deck)",
231
- options,
232
- index=None,
233
- placeholder="Type to search…",
234
- key="deck_selectbox",
235
- on_change=_add_selected_to_deck, # <- auto-add
236
- )
237
- if st.session_state["deck"]:
238
- # header row
239
- st.button("🗑️ Clear deck", on_click=lambda: st.session_state.update(deck=[]), use_container_width=True)
240
- h1, h2 = st.columns([6, 3])
241
- h1.markdown("**Card**")
242
- h2.markdown("**Remove?**")
243
- for i, card in enumerate(st.session_state["deck"]):
244
- name_col, rm_col = st.columns([6, 3], gap="small")
245
- name_col.write(card)
246
- with rm_col:
247
- if st.button("Remove", key=f"rm-deck-{i}", use_container_width=True):
248
- remove_card("deck", card)
249
- st.rerun()
250
- else:
251
- st.caption("Deck is empty.")
252
-
253
- with c2:
254
- st.subheader("Add to pack")
255
- pack_sel = st.selectbox(
256
- "Search card (pack)",
257
- options,
258
- index=None,
259
- placeholder="Type to search…",
260
- key="pack_selectbox",
261
- on_change=_add_selected_to_pack, # <- auto-add
262
- )
263
-
264
 
 
 
 
 
 
265
 
266
  if st.session_state["pack"]:
267
- # header row
268
- st.button("🗑️ Clear pack", on_click=lambda: st.session_state.update(pack=[]), use_container_width=True)
269
- h1, h2, h3 = st.columns([6, 2, 3])
270
- h1.markdown("**Card**")
271
- h2.markdown("**Score**")
272
- h3.markdown("**Pick?**")
273
-
274
- pack_list = st.session_state["pack"]
275
- vals = [scores.get(c) if scores and c in scores else np.nan for c in pack_list]
276
- logits = [logits.get(c) if logits and c in logits else np.nan for c in pack_list]
277
- df_scores = pd.DataFrame({"Card": pack_list, "Score": vals, "Logits": logits})
278
- df_scores = df_scores.sort_values("Score", ascending=False, na_position="last").reset_index(drop=True)
279
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
- # rows
282
- for i, row in df_scores.iterrows():
283
- card = row["Card"]
284
- score = row["Score"]
285
- logit = row["Logits"]
286
 
287
-
288
- c1, c2, c3 = st.columns([6, 2, 3], gap="small")
289
- c1.write(card)
 
 
 
 
 
 
 
 
 
 
290
 
291
- tooltip_html = f"""
292
- <div title="{logit:.4f}">
293
- <progress Value="{score}" max="1" style="width: 100%; height: 20px;"></progress>
294
- </div>
295
- """
296
- c2.markdown(tooltip_html, unsafe_allow_html=True)
297
- with c3:
298
- if st.button("Pick", key=f"pick_btn_{i}", use_container_width=True, help="Add to deck & clear pack"):
299
- push_undo()
300
- st.session_state["deck"].append(card)
301
- st.session_state["pack"] = []
302
- st.rerun()
303
- else:
304
- st.caption("Pack is empty.")
 
 
 
 
 
 
 
 
 
 
 
305
 
306
  # --- Tab 2: Card rankings ----------------------------------------------------
307
 
 
201
 
202
 
203
  # --- Tab 1: Draft -------------------------------------------------------
204
+ draft_area = st.empty()
205
  with tabs[0]:
206
+ with draft_area:
207
+ if st.session_state.get("set_code") == "EOE":
208
+ st.warning("The model is not trained for this set. Results may be inaccurate.", icon="⚠️")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
+ if st.session_state["undo_stack"]:
211
+ st.button("↩️ Undo last action", on_click=undo_last)
212
+
213
+ scores = {}
214
+ pick = None
215
 
216
  if st.session_state["pack"]:
217
+ pack = st.session_state["pack"]
218
+ deck = st.session_state["deck"]
219
+
220
+ try:
221
+ pick, logits, scores = rank_cards(deck, pack)
222
+ if pick:
223
+ st.success(f"💡 Suggested pick: **{pick}**", icon="✨")
224
+ except Exception as e:
225
+ st.error(f"Error calculating card rankings: {e}")
226
+
227
+ options = list(model.cards[set_code.lower()].keys())
228
+ c1, c2 = st.columns(2)
229
+ with c1:
230
+ st.subheader("Add to Deck")
231
+ deck_sel = st.selectbox(
232
+ "Search card (deck)",
233
+ options,
234
+ index=None,
235
+ placeholder="Type to search…",
236
+ key="deck_selectbox",
237
+ on_change=_add_selected_to_deck, # <- auto-add
238
+ )
239
+ if st.session_state["deck"]:
240
+ # header row
241
+ st.button("🗑️ Clear deck", on_click=lambda: st.session_state.update(deck=[]), use_container_width=True)
242
+ h1, h2 = st.columns([6, 3])
243
+ h1.markdown("**Card**")
244
+ h2.markdown("**Remove?**")
245
+ for i, card in enumerate(st.session_state["deck"]):
246
+ name_col, rm_col = st.columns([6, 3], gap="small")
247
+ name_col.write(card)
248
+ with rm_col:
249
+ if st.button("Remove", key=f"rm-deck-{i}", use_container_width=True):
250
+ remove_card("deck", card)
251
+ st.rerun()
252
+ else:
253
+ st.caption("Deck is empty.")
254
+
255
+ with c2:
256
+ st.subheader("Add to pack")
257
+ pack_sel = st.selectbox(
258
+ "Search card (pack)",
259
+ options,
260
+ index=None,
261
+ placeholder="Type to search…",
262
+ key="pack_selectbox",
263
+ on_change=_add_selected_to_pack, # <- auto-add
264
+ )
265
+
266
 
 
 
 
 
 
267
 
268
+ if st.session_state["pack"]:
269
+ # header row
270
+ st.button("🗑️ Clear pack", on_click=lambda: st.session_state.update(pack=[]), use_container_width=True)
271
+ h1, h2, h3 = st.columns([6, 2, 3])
272
+ h1.markdown("**Card**")
273
+ h2.markdown("**Score**")
274
+ h3.markdown("**Pick?**")
275
+
276
+ pack_list = st.session_state["pack"]
277
+ vals = [scores.get(c) if scores and c in scores else np.nan for c in pack_list]
278
+ logits = [logits.get(c) if logits and c in logits else np.nan for c in pack_list]
279
+ df_scores = pd.DataFrame({"Card": pack_list, "Score": vals, "Logits": logits})
280
+ df_scores = df_scores.sort_values("Score", ascending=False, na_position="last").reset_index(drop=True)
281
 
282
+
283
+ # rows
284
+ for i, row in df_scores.iterrows():
285
+ card = row["Card"]
286
+ score = row["Score"]
287
+ logit = row["Logits"]
288
+
289
+
290
+ c1, c2, c3 = st.columns([6, 2, 3], gap="small")
291
+ c1.write(card)
292
+
293
+ tooltip_html = f"""
294
+ <div title="{logit:.4f}">
295
+ <progress Value="{score}" max="1" style="width: 100%; height: 20px;"></progress>
296
+ </div>
297
+ """
298
+ c2.markdown(tooltip_html, unsafe_allow_html=True)
299
+ with c3:
300
+ if st.button("Pick", key=f"pick_btn_{i}", use_container_width=True, help="Add to deck & clear pack"):
301
+ push_undo()
302
+ st.session_state["deck"].append(card)
303
+ st.session_state["pack"] = []
304
+ st.rerun()
305
+ else:
306
+ st.caption("Pack is empty.")
307
 
308
  # --- Tab 2: Card rankings ----------------------------------------------------
309