poemsforaphrodite commited on
Commit
c3b78b5
1 Parent(s): 72ef1cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -25
app.py CHANGED
@@ -636,15 +636,19 @@ def show_tabular_data(df, co, country_code):
636
  st.success(f"Calculated relevancy scores for {len(selected_indices)} selected rows.")
637
  st.experimental_rerun()
638
 
639
- # Display column headers
640
- cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1]) # Removed the extra column for "Compare"
641
- headers = ['Select', 'Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Competitors']
642
  for col, header in zip(cols, headers):
643
  col.write(f"**{header}**")
644
 
 
 
 
 
645
  # Display each row
646
  for i, row in enumerate(df.iloc[start_idx:end_idx].itertuples(), start=start_idx):
647
- cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1]) # Removed the extra column for "Compare"
648
 
649
  # Checkbox for row selection
650
  cols[0].checkbox("", key=f"select_{i}", value=st.session_state.selected_rows[i],
@@ -662,9 +666,11 @@ def show_tabular_data(df, co, country_code):
662
  cols[6].write(f"{row.position:.1f}")
663
  cols[7].write(f"{row.relevancy_score:.4f}" if not pd.isna(row.relevancy_score) and row.relevancy_score != 0 else "N/A")
664
 
665
- # Competitors column
666
- competitor_button = cols[8].button("Show", key=f"comp_{i}", disabled=pd.isna(row.relevancy_score) or row.relevancy_score == 0)
667
- if competitor_button:
 
 
668
  st.write(f"Competitor Analysis for: {row.query}")
669
  with st.spinner('Analyzing competitors...'):
670
  results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
@@ -677,10 +683,10 @@ def show_tabular_data(df, co, country_code):
677
  results_df.loc[our_url_mask, 'Position'] = row.position
678
 
679
  # Create a custom style function to highlight only our URL's row
680
- def highlight_our_url(row):
681
- if 'Our URL' in row['URL']:
682
- return ['background-color: lightgreen'] * len(row)
683
- return [''] * len(row)
684
 
685
  # Apply the custom style and hide the index
686
  styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
@@ -708,20 +714,20 @@ def show_tabular_data(df, co, country_code):
708
  else:
709
  st.error(f"Our page '{row.page}' is not in the results. This indicates an error in fetching or processing the page.")
710
 
711
- # Add "Compare" button at the bottom of the competitors table
712
- st.markdown(
713
- """
714
- <style>
715
- .stButton > button {
716
- background-color: #008CBA;
717
- color: white;
718
- }
719
- </style>
720
- """,
721
- unsafe_allow_html=True
722
- )
723
- if st.button("Compare Your Relevancy Score to the Page In First Place", key=f"compare_{i}"):
724
- compare_with_top_result(row._asdict(), co, country_code)
725
 
726
  return df # Return the updated dataframe
727
 
 
636
  st.success(f"Calculated relevancy scores for {len(selected_indices)} selected rows.")
637
  st.experimental_rerun()
638
 
639
+ # Display column headers without the "Compare" column
640
+ cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1]) # Removed the extra column for "Compare"
641
+ headers = ['Select', 'Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score']
642
  for col, header in zip(cols, headers):
643
  col.write(f"**{header}**")
644
 
645
+ # Variable to track which row's competitors are being shown
646
+ if 'competitor_display' not in st.session_state:
647
+ st.session_state.competitor_display = {}
648
+
649
  # Display each row
650
  for i, row in enumerate(df.iloc[start_idx:end_idx].itertuples(), start=start_idx):
651
+ cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1]) # Removed the extra column for "Compare"
652
 
653
  # Checkbox for row selection
654
  cols[0].checkbox("", key=f"select_{i}", value=st.session_state.selected_rows[i],
 
666
  cols[6].write(f"{row.position:.1f}")
667
  cols[7].write(f"{row.relevancy_score:.4f}" if not pd.isna(row.relevancy_score) and row.relevancy_score != 0 else "N/A")
668
 
669
+ # Competitors column with "Show" button
670
+ show_competitor = cols[7].button("Show", key=f"comp_{i}", disabled=pd.isna(row.relevancy_score) or row.relevancy_score == 0)
671
+ if show_competitor:
672
+ st.session_state.competitor_display[i] = True
673
+ if st.session_state.competitor_display.get(i, False):
674
  st.write(f"Competitor Analysis for: {row.query}")
675
  with st.spinner('Analyzing competitors...'):
676
  results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
 
683
  results_df.loc[our_url_mask, 'Position'] = row.position
684
 
685
  # Create a custom style function to highlight only our URL's row
686
+ def highlight_our_url(row_style):
687
+ if 'Our URL' in row_style['URL']:
688
+ return ['background-color: lightgreen'] * len(row_style)
689
+ return [''] * len(row_style)
690
 
691
  # Apply the custom style and hide the index
692
  styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
 
714
  else:
715
  st.error(f"Our page '{row.page}' is not in the results. This indicates an error in fetching or processing the page.")
716
 
717
+ # "Compare" button placed below the competitors table
718
+ st.markdown(
719
+ """
720
+ <style>
721
+ .stButton > button {
722
+ background-color: #008CBA;
723
+ color: white;
724
+ }
725
+ </style>
726
+ """,
727
+ unsafe_allow_html=True
728
+ )
729
+ if st.button("Compare Your Relevancy Score to the Page In First Place", key=f"compare_{i}"):
730
+ compare_with_top_result(row._asdict(), co, country_code)
731
 
732
  return df # Return the updated dataframe
733