JermaineAI commited on
Commit
791364e
Β·
1 Parent(s): 7f49ccd

Revert interactive buttons: Return to static prediction cards

Browse files
Files changed (1) hide show
  1. app.py +12 -32
app.py CHANGED
@@ -132,40 +132,20 @@ def check_api_health() -> Dict:
132
  # =============================================================================
133
  # UI Components
134
  # =============================================================================
135
- def update_text(word):
136
- """Append clicked word to current context."""
137
- current = st.session_state.get('context_value', '')
138
- if current and not current.endswith(' '):
139
- new_text = f"{current} {word}"
140
- else:
141
- new_text = f"{current}{word}"
142
- st.session_state['context_value'] = new_text
143
-
144
- def render_predictions(predictions: List[Dict], model_name: str, key_prefix: str):
145
  if not predictions:
146
  st.warning(f"No predictions from {model_name}")
147
  return
148
 
149
- # Custom CSS for buttons to look like cards
150
- st.markdown("""
151
- <style>
152
- div.stButton > button {
153
- text-align: left;
154
- padding: 0.5rem 1rem;
155
- height: auto;
156
- }
157
- </style>
158
- """, unsafe_allow_html=True)
159
-
160
- for i, pred in enumerate(predictions):
161
  word = pred.get("word", "?")
162
  prob = pred.get("probability", 0)
163
-
164
- # Create a button for each prediction
165
- label = f"{word} ({prob:.1%})"
166
- if st.button(label, key=f"{key_prefix}_{i}", use_container_width=True):
167
- update_text(word)
168
- st.rerun()
169
 
170
  # =============================================================================
171
  # Main App
@@ -267,19 +247,19 @@ if context:
267
 
268
  with col1:
269
  st.markdown("### πŸ€– LSTM Neural Network")
270
- render_predictions(lstm_preds, "LSTM", "lstm_compare")
271
 
272
  with col2:
273
  st.markdown("### πŸ“Š Trigram Statistical")
274
- render_predictions(trigram_preds, "Trigram", "trigram_compare")
275
 
276
  elif "LSTM" in model_choice:
277
  st.markdown("### πŸ€– LSTM Predictions")
278
- render_predictions(lstm_preds, "LSTM", "lstm_only")
279
 
280
  else:
281
  st.markdown("### πŸ“Š Trigram Predictions")
282
- render_predictions(trigram_preds, "Trigram", "trigram_only")
283
 
284
  # Footer
285
  st.markdown("---")
 
132
  # =============================================================================
133
  # UI Components
134
  # =============================================================================
135
+ def render_predictions(predictions: List[Dict], model_name: str):
 
 
 
 
 
 
 
 
 
136
  if not predictions:
137
  st.warning(f"No predictions from {model_name}")
138
  return
139
 
140
+ for pred in predictions:
 
 
 
 
 
 
 
 
 
 
 
141
  word = pred.get("word", "?")
142
  prob = pred.get("probability", 0)
143
+ st.markdown(f"""
144
+ <div class="prediction-card">
145
+ <span class="word">{word}</span>
146
+ <span class="prob"> β€” {prob:.1%}</span>
147
+ </div>
148
+ """, unsafe_allow_html=True)
149
 
150
  # =============================================================================
151
  # Main App
 
247
 
248
  with col1:
249
  st.markdown("### πŸ€– LSTM Neural Network")
250
+ render_predictions(lstm_preds, "LSTM")
251
 
252
  with col2:
253
  st.markdown("### πŸ“Š Trigram Statistical")
254
+ render_predictions(trigram_preds, "Trigram")
255
 
256
  elif "LSTM" in model_choice:
257
  st.markdown("### πŸ€– LSTM Predictions")
258
+ render_predictions(lstm_preds, "LSTM")
259
 
260
  else:
261
  st.markdown("### πŸ“Š Trigram Predictions")
262
+ render_predictions(trigram_preds, "Trigram")
263
 
264
  # Footer
265
  st.markdown("---")