Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
437da00
1
Parent(s):
ca75c69
Update app.py
Browse files
app.py
CHANGED
@@ -475,61 +475,52 @@ def show_tabular_data(df, co):
|
|
475 |
start_idx = (st.session_state.current_page - 1) * rows_per_page
|
476 |
end_idx = start_idx + rows_per_page
|
477 |
|
478 |
-
#
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
st.
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
if our_rank == 1:
|
526 |
-
st.success("Your page has the highest relevancy score!")
|
527 |
-
elif our_rank <= 3:
|
528 |
-
st.info("Your page is among the top 3 most relevant results.")
|
529 |
-
elif our_rank > total_results / 2:
|
530 |
-
st.warning("Your page's relevancy score is in the lower half of the results. Consider optimizing your content.")
|
531 |
-
else:
|
532 |
-
st.error(f"Our page '{row['page']}' is not in the results. This indicates an error in fetching or processing the page.")
|
533 |
|
534 |
return df # Return the updated dataframe
|
535 |
|
|
|
475 |
start_idx = (st.session_state.current_page - 1) * rows_per_page
|
476 |
end_idx = start_idx + rows_per_page
|
477 |
|
478 |
+
# Prepare data for display
|
479 |
+
display_df = df.iloc[start_idx:end_idx].copy()
|
480 |
+
display_df['page'] = display_df['page'].apply(lambda x: x[:50] + '...' if len(x) > 50 else x)
|
481 |
+
display_df['ctr'] = display_df['ctr'].apply(lambda x: f"{x:.2%}")
|
482 |
+
display_df['position'] = display_df['position'].apply(lambda x: f"{x:.1f}")
|
483 |
+
display_df['relevancy_score'] = display_df['relevancy_score'].apply(lambda x: f"{x:.4f}" if pd.notnull(x) else "N/A")
|
484 |
+
|
485 |
+
# Display the table
|
486 |
+
st.table(display_df)
|
487 |
+
|
488 |
+
# Add calculate and show competitors buttons
|
489 |
+
for index, row in display_df.iterrows():
|
490 |
+
col1, col2 = st.columns(2)
|
491 |
+
with col1:
|
492 |
+
if pd.isna(row['relevancy_score']) or row['relevancy_score'] == "N/A":
|
493 |
+
if st.button("Calculate", key=f"calc_{index}"):
|
494 |
+
with st.spinner('Calculating...'):
|
495 |
+
score = calculate_single_relevancy(df.loc[index])
|
496 |
+
df.at[index, 'relevancy_score'] = score
|
497 |
+
st.experimental_rerun()
|
498 |
+
with col2:
|
499 |
+
if row['relevancy_score'] != "N/A":
|
500 |
+
if st.button("Show Competitors", key=f"comp_{index}"):
|
501 |
+
st.write(f"Competitor Analysis for: {row['query']}")
|
502 |
+
with st.spinner('Analyzing competitors...'):
|
503 |
+
results_df = analyze_competitors(df.loc[index], co)
|
504 |
+
results_df = results_df.sort_values('relevancy_score', ascending=False).reset_index(drop=True)
|
505 |
+
|
506 |
+
our_rank = results_df.index[results_df['url'] == row['page']].tolist()
|
507 |
+
if our_rank:
|
508 |
+
our_rank = our_rank[0] + 1
|
509 |
+
total_results = len(results_df)
|
510 |
+
our_score = results_df.loc[results_df['url'] == row['page'], 'relevancy_score'].values[0]
|
511 |
+
|
512 |
+
st.table(results_df)
|
513 |
+
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
514 |
+
st.write(f"Our relevancy score: {our_score:.4f}")
|
515 |
+
|
516 |
+
if our_rank == 1:
|
517 |
+
st.success("Your page has the highest relevancy score!")
|
518 |
+
elif our_rank <= 3:
|
519 |
+
st.info("Your page is among the top 3 most relevant results.")
|
520 |
+
elif our_rank > total_results / 2:
|
521 |
+
st.warning("Your page's relevancy score is in the lower half of the results. Consider optimizing your content.")
|
522 |
+
else:
|
523 |
+
st.error(f"Our page '{row['page']}' is not in the results. This indicates an error in fetching or processing the page.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
|
525 |
return df # Return the updated dataframe
|
526 |
|