cyberandy commited on
Commit
9e76632
Β·
verified Β·
1 Parent(s): 5c65b3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -38
app.py CHANGED
@@ -328,42 +328,62 @@ def create_gradio_interface() -> gr.Blocks:
328
 
329
  def format_markdown_report(report_text: str) -> str:
330
  """Format the report text with proper Markdown and styling"""
331
- lines = report_text.split('\n')
332
- formatted_lines = []
333
-
334
- for line in lines:
335
- # Handle headings
336
- if '=============================' in line:
337
- continue
338
- if '-----------------------------' in line:
339
- formatted_lines.append('---')
340
- continue
341
-
342
- # Handle star ratings
343
- if '[β˜…β˜…β˜…β˜…β˜†]' in line:
344
- line = line.replace('[β˜…β˜…β˜…β˜…β˜†]', '`β˜…β˜…β˜…β˜…β˜†`')
345
 
346
- # Handle section titles with emojis
347
- if any(emoji in line for emoji in ['πŸ“Š', 'πŸ”', 'πŸ“', 'πŸ”„', 'πŸ’°', 'πŸ“ˆ', 'πŸ”§']):
348
- formatted_lines.append('\n**' + line.strip() + '**\n')
349
- continue
350
-
351
- # Handle bullet points
352
- if line.strip().startswith('β€’'):
353
- line = line.replace('β€’', '-')
354
-
355
- formatted_lines.append(line)
356
-
357
- # Join the lines and add final formatting
358
- formatted_text = '\n'.join(formatted_lines)
359
-
360
- # Add spacing after section breaks
361
- formatted_text = formatted_text.replace('---\n', '---\n\n')
362
-
363
- # Ensure bullet points are properly spaced
364
- formatted_text = formatted_text.replace('\n-', '\n\n-')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
 
366
- return formatted_text
 
 
 
 
 
 
 
 
 
 
 
 
367
 
368
  async def run_analysis(api_key: str,
369
  website_url: str,
@@ -437,10 +457,8 @@ def create_gradio_interface() -> gr.Blocks:
437
  value="Results will appear here...",
438
  label="Analysis Results",
439
  elem_classes="analysis-output",
440
- sanitize_html=False, # Allow HTML for custom formatting
441
- line_breaks=True, # Preserve line breaks
442
- header_links=False, # Disable header links for cleaner look
443
- show_copy_button=True # Allow users to copy the report
444
  )
445
 
446
  analyze_button.click(
 
328
 
329
  def format_markdown_report(report_text: str) -> str:
330
  """Format the report text with proper Markdown and styling"""
331
+ # Extract just the report content using markers
332
+ try:
333
+ start_marker = "πŸ“Š E-COMMERCE ANALYSIS REPORT"
334
+ end_marker = "TECHNICAL INSIGHTS"
 
 
 
 
 
 
 
 
 
 
335
 
336
+ # Find the report content
337
+ start_idx = report_text.find(start_marker)
338
+ if start_idx == -1:
339
+ return "Error: Could not find report content"
340
+
341
+ # Extract and clean the report
342
+ report_lines = []
343
+ in_report = False
344
+ for line in report_text.split('\n'):
345
+ if start_marker in line:
346
+ in_report = True
347
+ report_lines.append("# " + line.strip())
348
+ continue
349
+
350
+ if in_report:
351
+ # Skip empty lines
352
+ if not line.strip():
353
+ continue
354
+
355
+ # Format section headers
356
+ if any(emoji in line for emoji in ['πŸ”', 'πŸ“', 'πŸ”„', 'πŸ’°', 'πŸ“ˆ', 'πŸ”§']):
357
+ if ":" in line:
358
+ title, score = line.split(":", 1)
359
+ report_lines.append(f"\n## {title.strip()}")
360
+ if score.strip():
361
+ report_lines.append(f"**Score: {score.strip()}**\n")
362
+ else:
363
+ report_lines.append(f"\n## {line.strip()}\n")
364
+ continue
365
+
366
+ # Format bullet points
367
+ if line.strip().startswith('β€’'):
368
+ report_lines.append(line.replace('β€’', '-'))
369
+ continue
370
+
371
+ # Add other lines as is
372
+ report_lines.append(line.strip())
373
 
374
+ # Join the lines and clean up the formatting
375
+ report_text = '\n'.join(report_lines)
376
+
377
+ # Clean up multiple blank lines
378
+ report_text = '\n'.join(line for line, _ in itertools.groupby(report_text.split('\n')))
379
+
380
+ # Ensure proper spacing around headers and bullet points
381
+ report_text = re.sub(r'\n#{1,2} ', r'\n\n# ', report_text)
382
+ report_text = re.sub(r'\n- ', r'\n\n- ', report_text)
383
+
384
+ return report_text
385
+ except Exception as e:
386
+ return f"Error formatting report: {str(e)}"
387
 
388
  async def run_analysis(api_key: str,
389
  website_url: str,
 
457
  value="Results will appear here...",
458
  label="Analysis Results",
459
  elem_classes="analysis-output",
460
+ show_copy_button=True,
461
+ line_breaks=True
 
 
462
  )
463
 
464
  analyze_button.click(