Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
3dc4358
1
Parent(s):
c3b78b5
Update app.py
Browse files
app.py
CHANGED
@@ -636,19 +636,15 @@ 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])
|
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])
|
652 |
|
653 |
# Checkbox for row selection
|
654 |
cols[0].checkbox("", key=f"select_{i}", value=st.session_state.selected_rows[i],
|
@@ -666,68 +662,69 @@ def show_tabular_data(df, co, country_code):
|
|
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
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
677 |
-
|
678 |
-
# Sort the results by Position in ascending order
|
679 |
-
results_df = results_df.sort_values('Position', ascending=True).reset_index(drop=True)
|
680 |
-
|
681 |
-
# Update the Position for our URL
|
682 |
-
our_url_mask = results_df['URL'].str.contains('Our URL')
|
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")
|
693 |
-
|
694 |
-
# Display the styled DataFrame
|
695 |
-
st.markdown(styled_df.to_html(), unsafe_allow_html=True)
|
696 |
-
|
697 |
-
# Extract our result for additional insights
|
698 |
-
our_result = results_df[results_df['URL'].str.contains('Our URL')]
|
699 |
-
|
700 |
-
if not our_result.empty:
|
701 |
-
our_rank = our_result['Position'].values[0]
|
702 |
-
total_results = len(results_df)
|
703 |
-
our_score = our_result['Score'].values[0]
|
704 |
|
705 |
-
|
706 |
-
|
707 |
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
731 |
|
732 |
return df # Return the updated dataframe
|
733 |
|
|
|
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])
|
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])
|
648 |
|
649 |
# Checkbox for row selection
|
650 |
cols[0].checkbox("", key=f"select_{i}", value=st.session_state.selected_rows[i],
|
|
|
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 |
+
if not pd.isna(row.relevancy_score) and row.relevancy_score != 0:
|
667 |
+
competitor_button = cols[8].button("Show", key=f"comp_{i}")
|
668 |
+
if competitor_button:
|
669 |
+
st.write(f"Competitor Analysis for: {row.query}")
|
670 |
+
with st.spinner('Analyzing competitors...'):
|
671 |
+
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
672 |
|
673 |
+
# Sort the results by Position in ascending order
|
674 |
+
results_df = results_df.sort_values('Position', ascending=True).reset_index(drop=True)
|
675 |
|
676 |
+
# Update the Position for our URL
|
677 |
+
our_url_mask = results_df['URL'].str.contains('Our URL')
|
678 |
+
results_df.loc[our_url_mask, 'Position'] = row.position
|
679 |
+
|
680 |
+
# Create a custom style function to highlight only our URL's row
|
681 |
+
def highlight_our_url(row):
|
682 |
+
if 'Our URL' in row['URL']:
|
683 |
+
return ['background-color: lightgreen'] * len(row)
|
684 |
+
return [''] * len(row)
|
685 |
+
|
686 |
+
# Apply the custom style and hide the index
|
687 |
+
styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
|
688 |
+
|
689 |
+
# Display the styled DataFrame
|
690 |
+
st.markdown(styled_df.to_html(), unsafe_allow_html=True)
|
691 |
+
|
692 |
+
# Extract our result for additional insights
|
693 |
+
our_result = results_df[results_df['URL'].str.contains('Our URL')]
|
694 |
+
|
695 |
+
if not our_result.empty:
|
696 |
+
our_rank = our_result['Position'].values[0]
|
697 |
+
total_results = len(results_df)
|
698 |
+
our_score = our_result['Score'].values[0]
|
699 |
+
|
700 |
+
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
701 |
+
st.write(f"Our relevancy score: {our_score:.4f}")
|
702 |
+
|
703 |
+
if our_rank == 1:
|
704 |
+
st.success("Your page has the highest relevancy score!")
|
705 |
+
elif our_rank <= 3:
|
706 |
+
st.info("Your page is among the top 3 most relevant results.")
|
707 |
+
elif our_rank > total_results / 2:
|
708 |
+
st.warning("Your page's relevancy score is in the lower half of the results. Consider optimizing your content.")
|
709 |
+
else:
|
710 |
+
st.error(f"Our page '{row.page}' is not in the results. This indicates an error in fetching or processing the page.")
|
711 |
+
|
712 |
+
# Add "Compare" button at the bottom of the competitors table
|
713 |
+
st.markdown(
|
714 |
+
"""
|
715 |
+
<style>
|
716 |
+
.stButton > button {
|
717 |
+
background-color: #008CBA;
|
718 |
+
color: white;
|
719 |
+
}
|
720 |
+
</style>
|
721 |
+
""",
|
722 |
+
unsafe_allow_html=True
|
723 |
+
)
|
724 |
+
if st.button("Compare Your Relevancy Score to the Page In First Place", key=f"compare_{i}"):
|
725 |
+
compare_with_top_result(row._asdict(), co, country_code)
|
726 |
+
else:
|
727 |
+
cols[8].write("N/A")
|
728 |
|
729 |
return df # Return the updated dataframe
|
730 |
|