Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
783a4dd
1
Parent(s):
8bc1009
Update app.py
Browse files
app.py
CHANGED
@@ -252,9 +252,9 @@ def analyze_competitors(row, co, custom_url=None, country_code=None):
|
|
252 |
competitor_url = normalize_url(data['url'])
|
253 |
score = calculate_relevance_score(data['content'], query, co)
|
254 |
results.append({
|
255 |
-
'
|
256 |
-
'
|
257 |
-
'
|
258 |
'is_our_url': competitor_url == our_url
|
259 |
})
|
260 |
|
@@ -263,23 +263,26 @@ def analyze_competitors(row, co, custom_url=None, country_code=None):
|
|
263 |
|
264 |
if not any(r['is_our_url'] for r in results):
|
265 |
results.append({
|
266 |
-
'
|
267 |
-
'
|
268 |
-
'
|
269 |
'is_our_url': True
|
270 |
})
|
271 |
|
272 |
# Sort results by position
|
273 |
-
results = sorted(results, key=lambda x: x['
|
274 |
|
275 |
-
# Create DataFrame
|
276 |
-
results_df = pd.DataFrame(results)
|
277 |
-
results_df['
|
278 |
-
|
279 |
-
|
|
|
|
|
280 |
)
|
281 |
-
|
282 |
-
|
|
|
283 |
|
284 |
return results_df
|
285 |
|
@@ -593,18 +596,20 @@ def show_tabular_data(df, co, country_code):
|
|
593 |
st.write(f"Competitor Analysis for: {row.query}")
|
594 |
with st.spinner('Analyzing competitors...'):
|
595 |
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
596 |
-
|
597 |
# Sort the results by Score in descending order
|
598 |
results_df = results_df.sort_values('Score', ascending=False).reset_index(drop=True)
|
599 |
|
600 |
# Find our page's rank
|
601 |
-
our_rank = results_df.index[results_df['URL'].str.contains('
|
602 |
if our_rank:
|
603 |
our_rank = our_rank[0] + 1 # Adding 1 because index starts at 0
|
604 |
total_results = len(results_df)
|
605 |
-
our_score = results_df.loc[results_df['URL'].str.contains('
|
|
|
|
|
|
|
606 |
|
607 |
-
st.dataframe(results_df)
|
608 |
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
609 |
st.write(f"Our relevancy score: {our_score:.4f}")
|
610 |
|
|
|
252 |
competitor_url = normalize_url(data['url'])
|
253 |
score = calculate_relevance_score(data['content'], query, co)
|
254 |
results.append({
|
255 |
+
'Position': data['position'],
|
256 |
+
'URL': competitor_url,
|
257 |
+
'Score': score,
|
258 |
'is_our_url': competitor_url == our_url
|
259 |
})
|
260 |
|
|
|
263 |
|
264 |
if not any(r['is_our_url'] for r in results):
|
265 |
results.append({
|
266 |
+
'Position': len(results) + 1,
|
267 |
+
'URL': our_url,
|
268 |
+
'Score': our_score,
|
269 |
'is_our_url': True
|
270 |
})
|
271 |
|
272 |
# Sort results by position
|
273 |
+
results = sorted(results, key=lambda x: x['Position'])
|
274 |
|
275 |
+
# Create DataFrame
|
276 |
+
results_df = pd.DataFrame(results)
|
277 |
+
results_df['Position'] = results_df['Position'].astype(int)
|
278 |
+
|
279 |
+
# Mark our URL
|
280 |
+
results_df['URL'] = results_df.apply(
|
281 |
+
lambda x: f"{x['URL']} (Our URL)" if x['is_our_url'] else x['URL'], axis=1
|
282 |
)
|
283 |
+
|
284 |
+
# Keep only the columns we want to display
|
285 |
+
results_df = results_df[['Position', 'URL', 'Score']]
|
286 |
|
287 |
return results_df
|
288 |
|
|
|
596 |
st.write(f"Competitor Analysis for: {row.query}")
|
597 |
with st.spinner('Analyzing competitors...'):
|
598 |
results_df = analyze_competitors(row._asdict(), co, country_code=country_code)
|
599 |
+
|
600 |
# Sort the results by Score in descending order
|
601 |
results_df = results_df.sort_values('Score', ascending=False).reset_index(drop=True)
|
602 |
|
603 |
# Find our page's rank
|
604 |
+
our_rank = results_df.index[results_df['URL'].str.contains('Our URL')].tolist()
|
605 |
if our_rank:
|
606 |
our_rank = our_rank[0] + 1 # Adding 1 because index starts at 0
|
607 |
total_results = len(results_df)
|
608 |
+
our_score = results_df.loc[results_df['URL'].str.contains('Our URL'), 'Score'].values[0]
|
609 |
+
|
610 |
+
# Display the styled DataFrame without index
|
611 |
+
st.dataframe(results_df.style.highlight_max(axis=0, color='lightgreen').hide_index())
|
612 |
|
|
|
613 |
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
614 |
st.write(f"Our relevancy score: {our_score:.4f}")
|
615 |
|