Spaces:
Sleeping
Sleeping
poemsforaphrodite
commited on
Commit
•
9b49b5b
1
Parent(s):
437da00
Update app.py
Browse files
app.py
CHANGED
@@ -475,52 +475,61 @@ 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 |
-
|
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 |
return df # Return the updated dataframe
|
526 |
|
|
|
475 |
start_idx = (st.session_state.current_page - 1) * rows_per_page
|
476 |
end_idx = start_idx + rows_per_page
|
477 |
|
478 |
+
# Display column headers
|
479 |
+
cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
|
480 |
+
headers = ['Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Competitors']
|
481 |
+
for col, header in zip(cols, headers):
|
482 |
+
col.write(f"**{header}**")
|
483 |
+
|
484 |
+
# Display each row
|
485 |
+
for index, row in df.iloc[start_idx:end_idx].iterrows():
|
486 |
+
cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
|
487 |
+
cols[0].write(row['page'])
|
488 |
+
cols[1].write(row['query'])
|
489 |
+
cols[2].write(row['clicks'])
|
490 |
+
cols[3].write(row['impressions'])
|
491 |
+
cols[4].write(f"{row['ctr']:.2%}")
|
492 |
+
cols[5].write(f"{row['position']:.1f}")
|
493 |
+
|
494 |
+
# Relevancy Score column
|
495 |
+
if pd.isna(row['relevancy_score']) or row['relevancy_score'] == 0:
|
496 |
+
if cols[6].button("Calculate", key=f"calc_{index}"):
|
497 |
+
with st.spinner('Calculating...'):
|
498 |
+
score = calculate_single_relevancy(row)
|
499 |
+
df.at[index, 'relevancy_score'] = score
|
500 |
+
st.experimental_rerun()
|
501 |
+
else:
|
502 |
+
cols[6].write(f"{row['relevancy_score']:.4f}")
|
503 |
+
|
504 |
+
# Competitors column
|
505 |
+
competitor_button = cols[7].button("Show Competitors", key=f"comp_{index}", disabled=pd.isna(row['relevancy_score']) or row['relevancy_score'] == 0)
|
506 |
+
if competitor_button:
|
507 |
+
st.write(f"Competitor Analysis for: {row['query']}")
|
508 |
+
with st.spinner('Analyzing competitors...'):
|
509 |
+
results_df = analyze_competitors(row, co)
|
510 |
+
|
511 |
+
# Sort the results by relevancy score in descending order
|
512 |
+
results_df = results_df.sort_values('relevancy_score', ascending=False).reset_index(drop=True)
|
513 |
+
|
514 |
+
# Find our page's rank
|
515 |
+
our_rank = results_df.index[results_df['url'] == row['page']].tolist()
|
516 |
+
if our_rank:
|
517 |
+
our_rank = our_rank[0] + 1 # Adding 1 because index starts at 0
|
518 |
+
total_results = len(results_df)
|
519 |
+
our_score = results_df.loc[results_df['url'] == row['page'], 'relevancy_score'].values[0]
|
520 |
+
|
521 |
+
st.dataframe(results_df)
|
522 |
+
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
523 |
+
st.write(f"Our relevancy score: {our_score:.4f}")
|
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 |
|