Spaces:
Running
Running
poemsforaphrodite
commited on
Commit
•
25bc4db
1
Parent(s):
816dd30
Update app.py
Browse files
app.py
CHANGED
@@ -242,7 +242,6 @@ def calculate_relevance_score(page_content, query, co):
|
|
242 |
return 0
|
243 |
|
244 |
def analyze_competitors(row, co, custom_url=None, country_code=None):
|
245 |
-
# logger.info(f"Analyzing competitors for query: {row['query']}")
|
246 |
query = row['query']
|
247 |
our_url = row['page']
|
248 |
|
@@ -267,50 +266,44 @@ def analyze_competitors(row, co, custom_url=None, country_code=None):
|
|
267 |
|
268 |
def show_competitor_analysis(row, co, country_code):
|
269 |
if st.button("Check Competitors", key=f"comp_{row['page']}"):
|
270 |
-
|
271 |
with st.spinner('Analyzing competitors...'):
|
272 |
results_df = analyze_competitors(row, co, country_code=country_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
st.write("Relevancy Score Comparison:")
|
274 |
-
st.
|
275 |
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
else:
|
290 |
-
our_rank = our_data.index[0] + 1
|
291 |
-
total_results = len(results_df)
|
292 |
-
our_score = our_data['relevancy_score'].values[0]
|
293 |
-
|
294 |
-
# logger.info(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
295 |
-
st.write(f"Our page ('{row['page']}') ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
296 |
-
st.write(f"Our relevancy score: {our_score:.4f}")
|
297 |
-
|
298 |
-
if our_score == 0:
|
299 |
-
st.warning("Our page's relevancy score is 0. This might indicate an issue with content fetching or score calculation.")
|
300 |
-
# Additional debugging information
|
301 |
-
# st.write("Debugging Information:")
|
302 |
-
# content = fetch_content(row['page'])
|
303 |
-
# st.json({
|
304 |
-
# "content_length": len(content),
|
305 |
-
# "content_preview": content[:500] if content else "No content fetched",
|
306 |
-
# "query": row['query']
|
307 |
-
# })
|
308 |
-
elif our_rank == 1:
|
309 |
-
st.success("Your page has the highest relevancy score!")
|
310 |
-
elif our_rank <= 3:
|
311 |
-
st.info("Your page is among the top 3 most relevant results.")
|
312 |
-
elif our_rank > total_results / 2:
|
313 |
-
st.warning("Your page's relevancy score is in the lower half of the results. Consider optimizing your content.")
|
314 |
|
315 |
def process_gsc_data(df):
|
316 |
#logging.info("Processing GSC data")
|
|
|
242 |
return 0
|
243 |
|
244 |
def analyze_competitors(row, co, custom_url=None, country_code=None):
|
|
|
245 |
query = row['query']
|
246 |
our_url = row['page']
|
247 |
|
|
|
266 |
|
267 |
def show_competitor_analysis(row, co, country_code):
|
268 |
if st.button("Check Competitors", key=f"comp_{row['page']}"):
|
269 |
+
st.write(f"Competitor Analysis for: {row['query']}")
|
270 |
with st.spinner('Analyzing competitors...'):
|
271 |
results_df = analyze_competitors(row, co, country_code=country_code)
|
272 |
+
|
273 |
+
# Remove duplicates and our site from the results
|
274 |
+
results_df = results_df.drop_duplicates(subset='url', keep='first')
|
275 |
+
our_result = results_df[results_df['url'] == row['page']]
|
276 |
+
competitor_results = results_df[results_df['url'] != row['page']]
|
277 |
+
|
278 |
+
# Combine results, with our result at its actual position
|
279 |
+
combined_results = pd.concat([competitor_results.iloc[:row['position']-1], our_result, competitor_results.iloc[row['position']-1:]])
|
280 |
+
combined_results = combined_results.reset_index(drop=True)
|
281 |
+
|
282 |
+
# Add position column, starting from 1
|
283 |
+
combined_results.insert(0, 'Position', range(1, len(combined_results) + 1))
|
284 |
+
|
285 |
+
# Format our result in bold
|
286 |
+
combined_results['URL'] = combined_results.apply(
|
287 |
+
lambda x: f"**{x['url']}**" if x['url'] == row['page'] else x['url'], axis=1
|
288 |
+
)
|
289 |
+
|
290 |
+
# Display the results
|
291 |
st.write("Relevancy Score Comparison:")
|
292 |
+
st.markdown(combined_results[['Position', 'URL', 'relevancy_score']].to_markdown(index=False), unsafe_allow_html=True)
|
293 |
|
294 |
+
our_rank = combined_results.index[combined_results['url'] == row['page']].tolist()[0] + 1
|
295 |
+
total_results = len(combined_results)
|
296 |
+
our_score = our_result['relevancy_score'].values[0]
|
297 |
+
|
298 |
+
st.write(f"Our page ranks {our_rank} out of {total_results} in terms of relevancy score.")
|
299 |
+
st.write(f"Our relevancy score: {our_score:.4f}")
|
300 |
+
|
301 |
+
if our_rank == 1:
|
302 |
+
st.success("Your page has the highest relevancy score!")
|
303 |
+
elif our_rank <= 3:
|
304 |
+
st.info("Your page is among the top 3 most relevant results.")
|
305 |
+
elif our_rank > total_results / 2:
|
306 |
+
st.warning("Your page's relevancy score is in the lower half of the results. Consider optimizing your content.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
def process_gsc_data(df):
|
309 |
#logging.info("Processing GSC data")
|