Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -247,6 +247,13 @@ def process_file(file_path):
|
|
247 |
|
248 |
plot_cluster_words(clustered_sentences)
|
249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
# Main code for UI
|
251 |
st.title("📺 Transcript Analysis 📊")
|
252 |
|
@@ -254,32 +261,17 @@ st.title("📺 Transcript Analysis 📊")
|
|
254 |
txt_files_df = get_txt_files()
|
255 |
st.write("Available .txt files:")
|
256 |
|
257 |
-
# Use st.
|
258 |
-
|
259 |
-
|
260 |
-
# Display the DataFrame and get the selected indices
|
261 |
-
selected_indices = df_placeholder.data_editor(
|
262 |
txt_files_df,
|
263 |
hide_index=True,
|
264 |
-
key="file_selector"
|
|
|
|
|
265 |
)
|
266 |
|
267 |
-
# Initialize session state for selected file if it doesn't exist
|
268 |
-
if 'selected_file' not in st.session_state:
|
269 |
-
st.session_state.selected_file = None
|
270 |
-
|
271 |
-
# Check if a new row is selected
|
272 |
-
if selected_indices and not selected_indices.empty:
|
273 |
-
selected_index = list(selected_indices.keys())[0]
|
274 |
-
selected_file = txt_files_df.iloc[selected_index]['File Name']
|
275 |
-
|
276 |
-
# Update session state only if a new file is selected
|
277 |
-
if st.session_state.selected_file != selected_file:
|
278 |
-
st.session_state.selected_file = selected_file
|
279 |
-
st.experimental_rerun()
|
280 |
-
|
281 |
# Display the selected file and process button
|
282 |
-
if st.session_state.selected_file:
|
283 |
st.write(f"Selected file: {st.session_state.selected_file}")
|
284 |
if st.button(f"Process {st.session_state.selected_file}"):
|
285 |
file_path = txt_files_df[txt_files_df['File Name'] == st.session_state.selected_file]['Full Path'].iloc[0]
|
|
|
247 |
|
248 |
plot_cluster_words(clustered_sentences)
|
249 |
|
250 |
+
def on_file_select():
|
251 |
+
selected_rows = st.session_state.file_selector['selected_rows']
|
252 |
+
if selected_rows:
|
253 |
+
st.session_state.selected_file = selected_rows[0]['File Name']
|
254 |
+
else:
|
255 |
+
st.session_state.selected_file = None
|
256 |
+
|
257 |
# Main code for UI
|
258 |
st.title("📺 Transcript Analysis 📊")
|
259 |
|
|
|
261 |
txt_files_df = get_txt_files()
|
262 |
st.write("Available .txt files:")
|
263 |
|
264 |
+
# Use st.data_editor() with on_change callback
|
265 |
+
st.data_editor(
|
|
|
|
|
|
|
266 |
txt_files_df,
|
267 |
hide_index=True,
|
268 |
+
key="file_selector",
|
269 |
+
on_change=on_file_select,
|
270 |
+
disabled=("Full Path",)
|
271 |
)
|
272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
# Display the selected file and process button
|
274 |
+
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
275 |
st.write(f"Selected file: {st.session_state.selected_file}")
|
276 |
if st.button(f"Process {st.session_state.selected_file}"):
|
277 |
file_path = txt_files_df[txt_files_df['File Name'] == st.session_state.selected_file]['Full Path'].iloc[0]
|