poemsforaphrodite commited on
Commit
8bf8b6f
1 Parent(s): 36a7b5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -182,7 +182,7 @@ def analyze_competitors(row, co):
182
  query = row['query']
183
  our_url = row['page']
184
 
185
- competitor_urls = get_serp_results(query)
186
 
187
  results = []
188
 
@@ -270,7 +270,7 @@ def analyze_competitors(row, co):
270
  our_url = row['page']
271
  our_score = row['relevancy_score']
272
 
273
- competitor_urls = get_serp_results(query)
274
 
275
  results = []
276
  for url in competitor_urls:
@@ -498,12 +498,31 @@ def show_tabular_data(df, co):
498
  score = calculate_relevance_score(content, row['query'], co)
499
  return score
500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  # Display the dataframe
502
  st.dataframe(df_display)
503
 
504
  # Create buttons for each row
505
  for index, row in df_display.iterrows():
506
- col1, col2 = st.columns([3, 1])
507
  with col1:
508
  st.write(f"Query: {row['query']} | Page: {row['page']}")
509
  with col2:
@@ -516,13 +535,11 @@ def show_tabular_data(df, co):
516
  st.experimental_rerun()
517
  else:
518
  st.write(f"Relevancy Score: {row['relevancy_score']:.4f}")
519
-
520
- # Add an expander for each row to show competitor analysis
521
- for index, row in df.iterrows():
522
- with st.expander(f"Analyze Competitors for: {row['query']} | {row['page']}"):
523
- if st.button("Analyze Competitors", key=f"comp_{index}"):
524
  with st.spinner('Analyzing competitors...'):
525
- results_df = analyze_competitors(row, co)
 
526
  st.dataframe(results_df)
527
 
528
  our_rank = results_df.index[results_df['url'] == row['page']].tolist()[0] + 1
 
182
  query = row['query']
183
  our_url = row['page']
184
 
185
+ competitor_urls = get_serp_results(query)[:5] # Get top 5 competitors
186
 
187
  results = []
188
 
 
270
  our_url = row['page']
271
  our_score = row['relevancy_score']
272
 
273
+ competitor_urls = get_serp_results(query)[:5] # Get top 5 competitors
274
 
275
  results = []
276
  for url in competitor_urls:
 
498
  score = calculate_relevance_score(content, row['query'], co)
499
  return score
500
 
501
+ # Function to analyze competitors
502
+ def analyze_competitors(row):
503
+ query = row['query']
504
+ our_url = row['page']
505
+ our_score = row['relevancy_score']
506
+
507
+ competitor_urls = get_serp_results(query)[:5] # Get top 5 competitors
508
+
509
+ results = []
510
+ for url in competitor_urls:
511
+ content = fetch_content(url)
512
+ score = calculate_relevance_score(content, query, co)
513
+ results.append({'url': url, 'relevancy_score': score})
514
+
515
+ results.append({'url': our_url, 'relevancy_score': our_score})
516
+ results_df = pd.DataFrame(results).sort_values('relevancy_score', ascending=False)
517
+
518
+ return results_df
519
+
520
  # Display the dataframe
521
  st.dataframe(df_display)
522
 
523
  # Create buttons for each row
524
  for index, row in df_display.iterrows():
525
+ col1, col2, col3 = st.columns([3, 1, 1])
526
  with col1:
527
  st.write(f"Query: {row['query']} | Page: {row['page']}")
528
  with col2:
 
535
  st.experimental_rerun()
536
  else:
537
  st.write(f"Relevancy Score: {row['relevancy_score']:.4f}")
538
+ with col3:
539
+ if st.button(f"Compare Competitors", key=f"comp_{index}"):
 
 
 
540
  with st.spinner('Analyzing competitors...'):
541
+ results_df = analyze_competitors(row)
542
+ st.write("Competitor Comparison:")
543
  st.dataframe(results_df)
544
 
545
  our_rank = results_df.index[results_df['url'] == row['page']].tolist()[0] + 1