poemsforaphrodite commited on
Commit
24e48ae
·
verified ·
1 Parent(s): 5fbb288

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -462,19 +462,27 @@ def show_tabular_data(df, co):
462
  score = calculate_relevance_score(content, row['query'], co)
463
  return score
464
 
465
- # Add a button column to the dataframe
466
- df_display['Calculate'] = ['Calculate' if pd.isna(score) or score == 0 else f"{score:.4f}" for score in df_display['relevancy_score']]
 
 
 
467
 
468
- # Display the dataframe
469
- st.dataframe(df_display)
470
-
471
- # Handle button clicks
472
  for index, row in df_display.iterrows():
473
- if st.button(f"Calculate {index}", key=f"calc_{index}"):
 
 
 
 
 
 
 
 
 
474
  score = calculate_single_relevancy(row)
475
  df.at[index, 'relevancy_score'] = score
476
  df_display.at[index, 'relevancy_score'] = score
477
- df_display.at[index, 'Calculate'] = f"{score:.4f}"
478
  st.experimental_rerun()
479
 
480
  if st.button("Show Competitor Analysis"):
 
462
  score = calculate_relevance_score(content, row['query'], co)
463
  return score
464
 
465
+ # Display column headers
466
+ cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
467
+ headers = ['Page', 'Query', 'Clicks', 'Impressions', 'CTR', 'Position', 'Relevancy Score', 'Calculate']
468
+ for col, header in zip(cols, headers):
469
+ col.write(f"**{header}**")
470
 
471
+ # Display each row
 
 
 
472
  for index, row in df_display.iterrows():
473
+ cols = st.columns([3, 2, 1, 1, 1, 1, 1, 1])
474
+ cols[0].write(row['page'])
475
+ cols[1].write(row['query'])
476
+ cols[2].write(row['clicks'])
477
+ cols[3].write(row['impressions'])
478
+ cols[4].write(f"{row['ctr']:.2%}")
479
+ cols[5].write(f"{row['position']:.1f}")
480
+ cols[6].write(f"{row['relevancy_score']:.4f}" if row['relevancy_score'] else "N/A")
481
+
482
+ if cols[7].button("Calculate", key=f"calc_{index}"):
483
  score = calculate_single_relevancy(row)
484
  df.at[index, 'relevancy_score'] = score
485
  df_display.at[index, 'relevancy_score'] = score
 
486
  st.experimental_rerun()
487
 
488
  if st.button("Show Competitor Analysis"):