Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
1307a20
1
Parent(s):
d079c96
Update app.py
Browse files
app.py
CHANGED
@@ -554,8 +554,19 @@ def show_tabular_data(df, co, country_code):
|
|
554 |
if 'selected_rows' not in st.session_state or len(st.session_state.selected_rows) != len(df):
|
555 |
st.session_state.selected_rows = [False] * len(df)
|
556 |
|
557 |
-
# Add a "Calculate Relevancy" button at the top
|
558 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
selected_indices = [i for i, selected in enumerate(st.session_state.selected_rows) if selected]
|
560 |
with st.spinner('Calculating relevancy scores...'):
|
561 |
for index in selected_indices:
|
@@ -565,14 +576,14 @@ def show_tabular_data(df, co, country_code):
|
|
565 |
st.experimental_rerun()
|
566 |
|
567 |
# Display column headers
|
568 |
-
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1
|
569 |
-
headers = ['Select', 'Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Competitors'
|
570 |
for col, header in zip(cols, headers):
|
571 |
col.write(f"**{header}**")
|
572 |
|
573 |
# Display each row
|
574 |
for i, row in enumerate(df.iloc[start_idx:end_idx].itertuples(), start=start_idx):
|
575 |
-
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1
|
576 |
|
577 |
# Checkbox for row selection
|
578 |
cols[0].checkbox("", key=f"select_{i}", value=st.session_state.selected_rows[i],
|
@@ -597,27 +608,32 @@ def show_tabular_data(df, co, country_code):
|
|
597 |
with st.spinner('Analyzing competitors...'):
|
598 |
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
599 |
|
600 |
-
# Sort the results by
|
601 |
-
results_df = results_df.sort_values('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
|
603 |
-
#
|
604 |
-
|
605 |
-
|
606 |
-
|
|
|
|
|
|
|
|
|
607 |
total_results = len(results_df)
|
608 |
-
our_score =
|
609 |
-
|
610 |
-
# Create a custom style function to highlight only our URL's row
|
611 |
-
def highlight_our_url(row):
|
612 |
-
if 'Our URL' in row['URL']:
|
613 |
-
return ['background-color: lightgreen'] * len(row)
|
614 |
-
return [''] * len(row)
|
615 |
-
|
616 |
-
# Apply the custom style and hide the index
|
617 |
-
styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
|
618 |
-
|
619 |
-
# Display the styled DataFrame
|
620 |
-
st.markdown(styled_df.to_html(), unsafe_allow_html=True)
|
621 |
|
622 |
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
623 |
st.write(f"Our relevancy score: {our_score:.4f}")
|
@@ -631,10 +647,20 @@ def show_tabular_data(df, co, country_code):
|
|
631 |
else:
|
632 |
st.error(f"Our page '{row.page}' is not in the results. This indicates an error in fetching or processing the page.")
|
633 |
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
638 |
|
639 |
return df # Return the updated dataframe
|
640 |
|
|
|
554 |
if 'selected_rows' not in st.session_state or len(st.session_state.selected_rows) != len(df):
|
555 |
st.session_state.selected_rows = [False] * len(df)
|
556 |
|
557 |
+
# Add a "Calculate Relevancy" button at the top with custom styling
|
558 |
+
st.markdown(
|
559 |
+
"""
|
560 |
+
<style>
|
561 |
+
.stButton > button {
|
562 |
+
background-color: #4CAF50;
|
563 |
+
color: white;
|
564 |
+
}
|
565 |
+
</style>
|
566 |
+
""",
|
567 |
+
unsafe_allow_html=True
|
568 |
+
)
|
569 |
+
if st.button("Click here to calculate relevancy for selected pages"):
|
570 |
selected_indices = [i for i, selected in enumerate(st.session_state.selected_rows) if selected]
|
571 |
with st.spinner('Calculating relevancy scores...'):
|
572 |
for index in selected_indices:
|
|
|
576 |
st.experimental_rerun()
|
577 |
|
578 |
# Display column headers
|
579 |
+
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1]) # Removed the extra column for "Compare"
|
580 |
+
headers = ['Select', 'Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Competitors']
|
581 |
for col, header in zip(cols, headers):
|
582 |
col.write(f"**{header}**")
|
583 |
|
584 |
# Display each row
|
585 |
for i, row in enumerate(df.iloc[start_idx:end_idx].itertuples(), start=start_idx):
|
586 |
+
cols = st.columns([0.5, 3, 2, 1, 1, 1, 1, 1, 1]) # Removed the extra column for "Compare"
|
587 |
|
588 |
# Checkbox for row selection
|
589 |
cols[0].checkbox("", key=f"select_{i}", value=st.session_state.selected_rows[i],
|
|
|
608 |
with st.spinner('Analyzing competitors...'):
|
609 |
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
610 |
|
611 |
+
# Sort the results by Position in ascending order
|
612 |
+
results_df = results_df.sort_values('Position', ascending=True).reset_index(drop=True)
|
613 |
+
|
614 |
+
# Update the Position for our URL
|
615 |
+
our_url_mask = results_df['URL'].str.contains('Our URL')
|
616 |
+
results_df.loc[our_url_mask, 'Position'] = row.position
|
617 |
+
|
618 |
+
# Create a custom style function to highlight only our URL's row
|
619 |
+
def highlight_our_url(row):
|
620 |
+
if 'Our URL' in row['URL']:
|
621 |
+
return ['background-color: lightgreen'] * len(row)
|
622 |
+
return [''] * len(row)
|
623 |
+
|
624 |
+
# Apply the custom style and hide the index
|
625 |
+
styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
|
626 |
|
627 |
+
# Display the styled DataFrame
|
628 |
+
st.markdown(styled_df.to_html(), unsafe_allow_html=True)
|
629 |
+
|
630 |
+
# Extract our result for additional insights
|
631 |
+
our_result = results_df[results_df['URL'].str.contains('Our URL')]
|
632 |
+
|
633 |
+
if not our_result.empty:
|
634 |
+
our_rank = our_result['Position'].values[0]
|
635 |
total_results = len(results_df)
|
636 |
+
our_score = our_result['Score'].values[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
|
638 |
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
639 |
st.write(f"Our relevancy score: {our_score:.4f}")
|
|
|
647 |
else:
|
648 |
st.error(f"Our page '{row.page}' is not in the results. This indicates an error in fetching or processing the page.")
|
649 |
|
650 |
+
# Add "Compare" button at the bottom of the competitors table
|
651 |
+
st.markdown(
|
652 |
+
"""
|
653 |
+
<style>
|
654 |
+
.stButton > button {
|
655 |
+
background-color: #008CBA;
|
656 |
+
color: white;
|
657 |
+
}
|
658 |
+
</style>
|
659 |
+
""",
|
660 |
+
unsafe_allow_html=True
|
661 |
+
)
|
662 |
+
if st.button("Compare Your Relevancy Score to the Page In First Place", key=f"compare_{i}"):
|
663 |
+
compare_with_top_result(row._asdict(), co, country_code)
|
664 |
|
665 |
return df # Return the updated dataframe
|
666 |
|