Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
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 |
-
#
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
#
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
441 |
-
line_breaks=True
|
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(
|