poemsforaphrodite commited on
Commit
a9c2ced
1 Parent(s): 67a6275

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -241,7 +241,7 @@ def calculate_relevance_score(page_content, query, co):
241
  def normalize_url(url):
242
  return url.rstrip('/').lower()
243
 
244
- def analyze_competitors(row, co, custom_url=None, country_code=None):
245
  query = row['query']
246
  our_url = normalize_url(row['page'])
247
 
@@ -258,8 +258,12 @@ def analyze_competitors(row, co, custom_url=None, country_code=None):
258
  'is_our_url': competitor_url == our_url
259
  })
260
 
261
- our_content = fetch_content(our_url, query)
262
- our_score = calculate_relevance_score(our_content, query, co)
 
 
 
 
263
 
264
  if not any(r['is_our_url'] for r in results):
265
  results.append({
@@ -519,7 +523,7 @@ def show_model_type_selector():
519
  key='model_type_selector'
520
  )
521
 
522
- def calculate_single_relevancy(row):
523
  page_content = fetch_content(row['page'], row['query'])
524
  query = row['query']
525
  score = calculate_relevance_score(page_content, query, co)
@@ -632,7 +636,7 @@ def show_tabular_data(df, co, country_code):
632
  with st.spinner('Calculating relevancy scores...'):
633
  for index in selected_indices:
634
  if pd.isna(df.iloc[index]['relevancy_score']) or df.iloc[index]['relevancy_score'] == 0:
635
- df.iloc[index, df.columns.get_loc('relevancy_score')] = calculate_single_relevancy(df.iloc[index])
636
  st.success(f"Calculated relevancy scores for {len(selected_indices)} selected rows.")
637
  st.experimental_rerun()
638
 
@@ -687,6 +691,9 @@ def show_tabular_data(df, co, country_code):
687
  our_url_mask = results_df['URL'].str.contains('Our URL')
688
  results_df.loc[our_url_mask, 'Position'] = row.position
689
 
 
 
 
690
  # Create a custom style function to highlight only our URL's row
691
  def highlight_our_url(row):
692
  if 'Our URL' in row['URL']:
 
241
  def normalize_url(url):
242
  return url.rstrip('/').lower()
243
 
244
+ def analyze_competitors(row, co, country_code):
245
  query = row['query']
246
  our_url = normalize_url(row['page'])
247
 
 
258
  'is_our_url': competitor_url == our_url
259
  })
260
 
261
+ # Use the existing relevancy score if available, otherwise calculate it
262
+ if pd.notna(row['relevancy_score']) and row['relevancy_score'] != 0:
263
+ our_score = row['relevancy_score']
264
+ else:
265
+ our_content = fetch_content(our_url, query)
266
+ our_score = calculate_relevance_score(our_content, query, co)
267
 
268
  if not any(r['is_our_url'] for r in results):
269
  results.append({
 
523
  key='model_type_selector'
524
  )
525
 
526
+ def calculate_single_relevancy(row, co):
527
  page_content = fetch_content(row['page'], row['query'])
528
  query = row['query']
529
  score = calculate_relevance_score(page_content, query, co)
 
636
  with st.spinner('Calculating relevancy scores...'):
637
  for index in selected_indices:
638
  if pd.isna(df.iloc[index]['relevancy_score']) or df.iloc[index]['relevancy_score'] == 0:
639
+ df.iloc[index, df.columns.get_loc('relevancy_score')] = calculate_single_relevancy(df.iloc[index], co)
640
  st.success(f"Calculated relevancy scores for {len(selected_indices)} selected rows.")
641
  st.experimental_rerun()
642
 
 
691
  our_url_mask = results_df['URL'].str.contains('Our URL')
692
  results_df.loc[our_url_mask, 'Position'] = row.position
693
 
694
+ # Ensure our URL's score matches the main table
695
+ results_df.loc[our_url_mask, 'Score'] = row.relevancy_score
696
+
697
  # Create a custom style function to highlight only our URL's row
698
  def highlight_our_url(row):
699
  if 'Our URL' in row['URL']: