ryanshelley commited on
Commit
4022ccc
Β·
verified Β·
1 Parent(s): be9c792

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -333,17 +333,21 @@ class SEOContentAnalyzer:
333
  async def run_seo_analysis(api_key: str, keyword: str, client_url: str, competitor_urls_text: str, progress=gr.Progress()):
334
  """Main function to run SEO analysis"""
335
 
 
 
 
 
336
  if not api_key:
337
- return "❌ Please provide your OpenAI API key", "", ""
338
 
339
  if not keyword or not client_url:
340
- return "❌ Please provide both keyword and client URL", "", ""
341
 
342
  # Parse competitor URLs
343
  competitor_urls = [url.strip() for url in competitor_urls_text.split('\n') if url.strip()]
344
 
345
  if not competitor_urls:
346
- return "❌ Please provide at least one competitor URL", "", ""
347
 
348
  try:
349
  progress(0.1, desc="Initializing analyzer...")
@@ -353,10 +357,10 @@ async def run_seo_analysis(api_key: str, keyword: str, client_url: str, competit
353
  crawl_data = await analyzer.crawl_all_urls(client_url, competitor_urls)
354
 
355
  if not crawl_data['client']:
356
- return "❌ Failed to crawl client URL", "", ""
357
 
358
  if not crawl_data['competitors']:
359
- return "❌ Failed to crawl any competitor URLs", "", ""
360
 
361
  progress(0.4, desc="Processing content...")
362
  chunks = analyzer.chunk_content(crawl_data)
@@ -401,7 +405,7 @@ async def run_seo_analysis(api_key: str, keyword: str, client_url: str, competit
401
  return report, summary_df, top_content_df
402
 
403
  except Exception as e:
404
- return f"❌ Error during analysis: {str(e)}", "", ""
405
 
406
  def sync_run_seo_analysis(*args):
407
  """Synchronous wrapper for the async function"""
@@ -409,7 +413,7 @@ def sync_run_seo_analysis(*args):
409
 
410
  # Create Gradio Interface
411
  def create_interface():
412
- with gr.Blocks(title="SEO Content Gap Analysis", theme=gr.themes.Soft()) as demo:
413
  gr.Markdown("""
414
  # πŸ” SEO Content Gap Analysis Tool
415
 
@@ -467,13 +471,15 @@ def create_interface():
467
  with gr.TabItem("πŸ“ˆ Page Summary"):
468
  summary_output = gr.Dataframe(
469
  label="Page Performance Summary",
470
- headers=["URL", "Type", "Total Chunks", "Avg Similarity", "Max Similarity"]
 
471
  )
472
 
473
  with gr.TabItem("🎯 Top Content"):
474
  top_content_output = gr.Dataframe(
475
  label="Top Performing Content Sections",
476
- headers=["Rank", "Type", "Score", "Content Preview", "URL"]
 
477
  )
478
 
479
  # Example section
 
333
  async def run_seo_analysis(api_key: str, keyword: str, client_url: str, competitor_urls_text: str, progress=gr.Progress()):
334
  """Main function to run SEO analysis"""
335
 
336
+ # Create empty dataframes for error cases
337
+ empty_summary_df = pd.DataFrame(columns=["URL", "Type", "Total Chunks", "Avg Similarity", "Max Similarity"])
338
+ empty_content_df = pd.DataFrame(columns=["Rank", "Type", "Score", "Content Preview", "URL"])
339
+
340
  if not api_key:
341
+ return "❌ Please provide your OpenAI API key", empty_summary_df, empty_content_df
342
 
343
  if not keyword or not client_url:
344
+ return "❌ Please provide both keyword and client URL", empty_summary_df, empty_content_df
345
 
346
  # Parse competitor URLs
347
  competitor_urls = [url.strip() for url in competitor_urls_text.split('\n') if url.strip()]
348
 
349
  if not competitor_urls:
350
+ return "❌ Please provide at least one competitor URL", empty_summary_df, empty_content_df
351
 
352
  try:
353
  progress(0.1, desc="Initializing analyzer...")
 
357
  crawl_data = await analyzer.crawl_all_urls(client_url, competitor_urls)
358
 
359
  if not crawl_data['client']:
360
+ return "❌ Failed to crawl client URL", empty_summary_df, empty_content_df
361
 
362
  if not crawl_data['competitors']:
363
+ return "❌ Failed to crawl any competitor URLs", empty_summary_df, empty_content_df
364
 
365
  progress(0.4, desc="Processing content...")
366
  chunks = analyzer.chunk_content(crawl_data)
 
405
  return report, summary_df, top_content_df
406
 
407
  except Exception as e:
408
+ return f"❌ Error during analysis: {str(e)}", empty_summary_df, empty_content_df
409
 
410
  def sync_run_seo_analysis(*args):
411
  """Synchronous wrapper for the async function"""
 
413
 
414
  # Create Gradio Interface
415
  def create_interface():
416
+ with gr.Blocks(title="SEO Content Gap Analysis", theme=gr.themes.Monochrome()) as demo:
417
  gr.Markdown("""
418
  # πŸ” SEO Content Gap Analysis Tool
419
 
 
471
  with gr.TabItem("πŸ“ˆ Page Summary"):
472
  summary_output = gr.Dataframe(
473
  label="Page Performance Summary",
474
+ headers=["URL", "Type", "Total Chunks", "Avg Similarity", "Max Similarity"],
475
+ value=pd.DataFrame(columns=["URL", "Type", "Total Chunks", "Avg Similarity", "Max Similarity"])
476
  )
477
 
478
  with gr.TabItem("🎯 Top Content"):
479
  top_content_output = gr.Dataframe(
480
  label="Top Performing Content Sections",
481
+ headers=["Rank", "Type", "Score", "Content Preview", "URL"],
482
+ value=pd.DataFrame(columns=["Rank", "Type", "Score", "Content Preview", "URL"])
483
  )
484
 
485
  # Example section