poemsforaphrodite commited on
Commit
3c85ea8
1 Parent(s): 79bf53f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -177,33 +177,25 @@ def analyze_competitors(row, co):
177
 
178
  results = []
179
  for url in competitor_urls:
180
- # Skip URLs that are not actual web pages
181
- if url.startswith('/search') or not url.startswith('http'):
182
- continue
183
  content = fetch_content(url)
184
  score = calculate_relevance_score(content, query, co)
185
  results.append({'url': url, 'relevancy_score': score})
186
 
187
- # Add our page to the results
188
  results.append({'url': our_url, 'relevancy_score': our_score})
189
-
190
- # Sort results by relevancy score in descending order
191
  results_df = pd.DataFrame(results).sort_values('relevancy_score', ascending=False)
192
 
193
- # Calculate our rank
194
- our_rank = results_df.index[results_df['url'] == our_url].tolist()[0] + 1
195
-
196
  logger.info(f"Competitor analysis completed. {len(results)} results obtained.")
197
- return results_df, our_rank
198
 
199
  def show_competitor_analysis(row, co):
200
  if st.button("Check Competitors", key=f"comp_{row['page']}"):
201
  logger.info(f"Competitor analysis requested for page: {row['page']}")
202
  with st.spinner('Analyzing competitors...'):
203
- results_df, our_rank = analyze_competitors(row, co)
204
  st.write("Relevancy Score Comparison:")
205
  st.dataframe(results_df)
206
 
 
207
  logger.info(f"Our page ranks {our_rank} out of {len(results_df)} in terms of relevancy score.")
208
  st.write(f"Our page ranks {our_rank} out of {len(results_df)} in terms of relevancy score.")
209
 
@@ -446,7 +438,13 @@ def show_tabular_data(df, co):
446
 
447
  with col2:
448
  st.write("Competitor Analysis:")
449
- show_competitor_analysis(row, co)
 
 
 
 
 
 
450
 
451
 
452
 
 
177
 
178
  results = []
179
  for url in competitor_urls:
 
 
 
180
  content = fetch_content(url)
181
  score = calculate_relevance_score(content, query, co)
182
  results.append({'url': url, 'relevancy_score': score})
183
 
 
184
  results.append({'url': our_url, 'relevancy_score': our_score})
 
 
185
  results_df = pd.DataFrame(results).sort_values('relevancy_score', ascending=False)
186
 
 
 
 
187
  logger.info(f"Competitor analysis completed. {len(results)} results obtained.")
188
+ return results_df
189
 
190
  def show_competitor_analysis(row, co):
191
  if st.button("Check Competitors", key=f"comp_{row['page']}"):
192
  logger.info(f"Competitor analysis requested for page: {row['page']}")
193
  with st.spinner('Analyzing competitors...'):
194
+ results_df = analyze_competitors(row, co)
195
  st.write("Relevancy Score Comparison:")
196
  st.dataframe(results_df)
197
 
198
+ our_rank = results_df.index[results_df['url'] == row['page']].tolist()[0] + 1
199
  logger.info(f"Our page ranks {our_rank} out of {len(results_df)} in terms of relevancy score.")
200
  st.write(f"Our page ranks {our_rank} out of {len(results_df)} in terms of relevancy score.")
201
 
 
438
 
439
  with col2:
440
  st.write("Competitor Analysis:")
441
+ if st.button("Analyze Competitors", key=f"comp_{index}"):
442
+ with st.spinner('Analyzing competitors...'):
443
+ results_df = analyze_competitors(row, co)
444
+ st.dataframe(results_df)
445
+
446
+ our_rank = results_df.index[results_df['url'] == row['page']].tolist()[0] + 1
447
+ st.write(f"Our page ranks {our_rank} out of {len(results_df)} in terms of relevancy score.")
448
 
449
 
450