Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
72ef1cc
1
Parent(s):
8723530
Update app.py
Browse files
app.py
CHANGED
@@ -637,14 +637,14 @@ def show_tabular_data(df, co, country_code):
|
|
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],
|
@@ -663,7 +663,8 @@ def show_tabular_data(df, co, country_code):
|
|
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 |
-
|
|
|
667 |
st.write(f"Competitor Analysis for: {row.query}")
|
668 |
with st.spinner('Analyzing competitors...'):
|
669 |
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
@@ -685,7 +686,7 @@ def show_tabular_data(df, co, country_code):
|
|
685 |
styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
|
686 |
|
687 |
# Display the styled DataFrame
|
688 |
-
st.markdown(styled_df.to_html(
|
689 |
|
690 |
# Extract our result for additional insights
|
691 |
our_result = results_df[results_df['URL'].str.contains('Our URL')]
|
@@ -707,20 +708,20 @@ def show_tabular_data(df, co, country_code):
|
|
707 |
else:
|
708 |
st.error(f"Our page '{row.page}' is not in the results. This indicates an error in fetching or processing the page.")
|
709 |
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
|
725 |
return df # Return the updated dataframe
|
726 |
|
|
|
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],
|
|
|
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)
|
|
|
686 |
styled_df = results_df.style.apply(highlight_our_url, axis=1).hide(axis="index")
|
687 |
|
688 |
# Display the styled DataFrame
|
689 |
+
st.markdown(styled_df.to_html(), unsafe_allow_html=True)
|
690 |
|
691 |
# Extract our result for additional insights
|
692 |
our_result = results_df[results_df['URL'].str.contains('Our URL')]
|
|
|
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 |
|