Spaces:
Build error
Build error
Update app/ui.py
Browse files
app/ui.py
CHANGED
|
@@ -83,17 +83,37 @@ with st.sidebar.expander("Select Dataset & Topic Model", expanded=True):
|
|
| 83 |
selected_dataset = st.selectbox("Dataset", datasets, help="Choose an available dataset.")
|
| 84 |
selected_model = st.selectbox("Model", AVAILABLE_MODELS, help="Select topic model architecture.")
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# Resolve paths
|
| 87 |
dataset_path = os.path.join(DATA_DIR, selected_dataset)
|
| 88 |
model_path = os.path.join(dataset_path, selected_model)
|
| 89 |
-
docs_path = os.path.join(dataset_path, "docs.jsonl")
|
| 90 |
vocab_path = os.path.join(dataset_path, "processed/vocab.txt")
|
| 91 |
time2id_path = os.path.join(dataset_path, "processed/time2id.txt")
|
|
|
|
|
|
|
|
|
|
| 92 |
index_path = os.path.join(dataset_path, "inverted_index.json")
|
| 93 |
beta_path = os.path.join(model_path, "beta.npy")
|
| 94 |
label_cache_path = os.path.join(model_path, "topic_label_cache.json")
|
| 95 |
-
|
| 96 |
-
lemma_map_path = os.path.join(dataset_path, "processed/lemma_to_forms.json")
|
| 97 |
|
| 98 |
with st.sidebar.expander("LLM Settings", expanded=True):
|
| 99 |
provider = st.selectbox("LLM Provider", options=list(ENV_VAR_MAP.keys()), help="Choose the LLM backend.")
|
|
@@ -256,15 +276,26 @@ if selected_words:
|
|
| 256 |
for i, word in enumerate(selected_words):
|
| 257 |
trend = get_word_trend(beta, vocab, word, topic_id=selected_topic)
|
| 258 |
color = color_cycle[i % len(color_cycle)]
|
|
|
|
| 259 |
fig.add_trace(go.Scatter(
|
| 260 |
x=time_labels,
|
| 261 |
y=trend,
|
| 262 |
name=word,
|
|
|
|
| 263 |
line=dict(color=color),
|
| 264 |
legendgroup=word,
|
| 265 |
showlegend=True
|
| 266 |
))
|
| 267 |
-
fig.update_layout(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
_, chart_col, _ = st.columns([0.2, 0.6, 0.2])
|
| 269 |
with chart_col:
|
| 270 |
st.plotly_chart(fig, use_container_width=True)
|
|
|
|
| 83 |
selected_dataset = st.selectbox("Dataset", datasets, help="Choose an available dataset.")
|
| 84 |
selected_model = st.selectbox("Model", AVAILABLE_MODELS, help="Select topic model architecture.")
|
| 85 |
|
| 86 |
+
# Check if the dataset has changed and reset session state if it has.
|
| 87 |
+
if 'current_dataset' not in st.session_state or st.session_state.current_dataset != selected_dataset:
|
| 88 |
+
st.session_state.current_dataset = selected_dataset
|
| 89 |
+
# List all session state keys that depend on the dataset
|
| 90 |
+
keys_to_clear = [
|
| 91 |
+
"selected_words",
|
| 92 |
+
"interesting_words",
|
| 93 |
+
"word_counts_multiselect",
|
| 94 |
+
"collected_deduplicated_docs",
|
| 95 |
+
"summary",
|
| 96 |
+
"context_for_followup",
|
| 97 |
+
"followup_history"
|
| 98 |
+
]
|
| 99 |
+
for key in keys_to_clear:
|
| 100 |
+
if key in st.session_state:
|
| 101 |
+
del st.session_state[key]
|
| 102 |
+
# Rerun the script to apply the clean state
|
| 103 |
+
st.rerun()
|
| 104 |
+
|
| 105 |
# Resolve paths
|
| 106 |
dataset_path = os.path.join(DATA_DIR, selected_dataset)
|
| 107 |
model_path = os.path.join(dataset_path, selected_model)
|
|
|
|
| 108 |
vocab_path = os.path.join(dataset_path, "processed/vocab.txt")
|
| 109 |
time2id_path = os.path.join(dataset_path, "processed/time2id.txt")
|
| 110 |
+
length_stats_path = os.path.join(dataset_path, "processed/length_stats.json")
|
| 111 |
+
lemma_map_path = os.path.join(dataset_path, "processed/lemma_to_forms.json")
|
| 112 |
+
docs_path = os.path.join(dataset_path, "docs.jsonl")
|
| 113 |
index_path = os.path.join(dataset_path, "inverted_index.json")
|
| 114 |
beta_path = os.path.join(model_path, "beta.npy")
|
| 115 |
label_cache_path = os.path.join(model_path, "topic_label_cache.json")
|
| 116 |
+
|
|
|
|
| 117 |
|
| 118 |
with st.sidebar.expander("LLM Settings", expanded=True):
|
| 119 |
provider = st.selectbox("LLM Provider", options=list(ENV_VAR_MAP.keys()), help="Choose the LLM backend.")
|
|
|
|
| 276 |
for i, word in enumerate(selected_words):
|
| 277 |
trend = get_word_trend(beta, vocab, word, topic_id=selected_topic)
|
| 278 |
color = color_cycle[i % len(color_cycle)]
|
| 279 |
+
# --- START: Modify this line ---
|
| 280 |
fig.add_trace(go.Scatter(
|
| 281 |
x=time_labels,
|
| 282 |
y=trend,
|
| 283 |
name=word,
|
| 284 |
+
mode='lines+markers', # Explicitly add markers to the lines
|
| 285 |
line=dict(color=color),
|
| 286 |
legendgroup=word,
|
| 287 |
showlegend=True
|
| 288 |
))
|
| 289 |
+
fig.update_layout(
|
| 290 |
+
title="",
|
| 291 |
+
xaxis_title="Year",
|
| 292 |
+
yaxis_title="Importance",
|
| 293 |
+
legend=dict(
|
| 294 |
+
font=dict(
|
| 295 |
+
size=16
|
| 296 |
+
)
|
| 297 |
+
)
|
| 298 |
+
)
|
| 299 |
_, chart_col, _ = st.columns([0.2, 0.6, 0.2])
|
| 300 |
with chart_col:
|
| 301 |
st.plotly_chart(fig, use_container_width=True)
|