Spaces:
Sleeping
Sleeping
Commit Β·
791364e
1
Parent(s): 7f49ccd
Revert interactive buttons: Return to static prediction cards
Browse files
app.py
CHANGED
|
@@ -132,40 +132,20 @@ def check_api_health() -> Dict:
|
|
| 132 |
# =============================================================================
|
| 133 |
# UI Components
|
| 134 |
# =============================================================================
|
| 135 |
-
def
|
| 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 |
-
|
| 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 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 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"
|
| 271 |
|
| 272 |
with col2:
|
| 273 |
st.markdown("### π Trigram Statistical")
|
| 274 |
-
render_predictions(trigram_preds, "Trigram"
|
| 275 |
|
| 276 |
elif "LSTM" in model_choice:
|
| 277 |
st.markdown("### π€ LSTM Predictions")
|
| 278 |
-
render_predictions(lstm_preds, "LSTM"
|
| 279 |
|
| 280 |
else:
|
| 281 |
st.markdown("### π Trigram Predictions")
|
| 282 |
-
render_predictions(trigram_preds, "Trigram"
|
| 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("---")
|