Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
9f4df6e
1
Parent(s):
0b016f9
Update app.py
Browse files
app.py
CHANGED
@@ -628,12 +628,16 @@ def show_tabular_data(df, co, country_code):
|
|
628 |
)
|
629 |
if st.button("Click here to calculate relevancy for selected pages"):
|
630 |
selected_indices = [i for i, selected in enumerate(st.session_state.selected_rows) if selected]
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
|
|
|
|
|
|
|
|
637 |
|
638 |
# Display column headers
|
639 |
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1])
|
@@ -645,10 +649,9 @@ def show_tabular_data(df, co, country_code):
|
|
645 |
for i, row in enumerate(df.iloc[start_idx:end_idx].itertuples(), start=start_idx):
|
646 |
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1])
|
647 |
|
648 |
-
# Checkbox for row selection
|
649 |
cols[0].checkbox("Select", key=f"select_{i}", value=st.session_state.selected_rows[i],
|
650 |
-
on_change=lambda idx=i:
|
651 |
-
[True if j == idx else x for j, x in enumerate(st.session_state.selected_rows)]))
|
652 |
|
653 |
# Truncate and make the URL clickable
|
654 |
truncated_url = row.page[:30] + '...' if len(row.page) > 30 else row.page
|
@@ -731,6 +734,9 @@ def show_tabular_data(df, co, country_code):
|
|
731 |
|
732 |
return df # Return the updated dataframe
|
733 |
|
|
|
|
|
|
|
734 |
def show_date_range_selector():
|
735 |
# logging.info("Showing date range selector")
|
736 |
return st.selectbox(
|
@@ -883,7 +889,8 @@ def main():
|
|
883 |
if st.session_state.report_data is not None and not st.session_state.report_data.empty:
|
884 |
st.write("Data fetched successfully.")
|
885 |
|
886 |
-
|
|
|
887 |
|
888 |
download_csv_link(st.session_state.report_data)
|
889 |
elif st.session_state.report_data is not None:
|
|
|
628 |
)
|
629 |
if st.button("Click here to calculate relevancy for selected pages"):
|
630 |
selected_indices = [i for i, selected in enumerate(st.session_state.selected_rows) if selected]
|
631 |
+
if selected_indices:
|
632 |
+
progress_bar = st.progress(0)
|
633 |
+
for i, index in enumerate(selected_indices):
|
634 |
+
if pd.isna(df.at[index, 'relevancy_score']) or df.at[index, 'relevancy_score'] == 0:
|
635 |
+
df.at[index, 'relevancy_score'] = calculate_single_relevancy(df.iloc[index])
|
636 |
+
progress_bar.progress((i + 1) / len(selected_indices))
|
637 |
+
st.success(f"Calculated relevancy scores for {len(selected_indices)} selected rows.")
|
638 |
+
st.session_state.report_data = df # Update the report_data in session state
|
639 |
+
else:
|
640 |
+
st.warning("No rows selected. Please select at least one row to calculate relevancy.")
|
641 |
|
642 |
# Display column headers
|
643 |
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1])
|
|
|
649 |
for i, row in enumerate(df.iloc[start_idx:end_idx].itertuples(), start=start_idx):
|
650 |
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1])
|
651 |
|
652 |
+
# Checkbox for row selection
|
653 |
cols[0].checkbox("Select", key=f"select_{i}", value=st.session_state.selected_rows[i],
|
654 |
+
on_change=lambda idx=i: update_selected_rows(idx))
|
|
|
655 |
|
656 |
# Truncate and make the URL clickable
|
657 |
truncated_url = row.page[:30] + '...' if len(row.page) > 30 else row.page
|
|
|
734 |
|
735 |
return df # Return the updated dataframe
|
736 |
|
737 |
+
def update_selected_rows(idx):
|
738 |
+
st.session_state.selected_rows[idx] = not st.session_state.selected_rows[idx]
|
739 |
+
|
740 |
def show_date_range_selector():
|
741 |
# logging.info("Showing date range selector")
|
742 |
return st.selectbox(
|
|
|
889 |
if st.session_state.report_data is not None and not st.session_state.report_data.empty:
|
890 |
st.write("Data fetched successfully.")
|
891 |
|
892 |
+
updated_df = show_tabular_data(st.session_state.report_data, co, country_code)
|
893 |
+
st.session_state.report_data = updated_df # Update the report_data with the potentially modified dataframe
|
894 |
|
895 |
download_csv_link(st.session_state.report_data)
|
896 |
elif st.session_state.report_data is not None:
|