Spaces:
Sleeping
Sleeping
| # interface/display.py | |
| from typing import Dict, List | |
| import json | |
| class DisplayFormatter: | |
| def format_error(error_msg: str) -> Dict: | |
| """Format error messages for display""" | |
| return { | |
| 'status': 'error', | |
| 'content': f""" | |
| ### β Error | |
| {error_msg} | |
| Please try again or contact support if the issue persists. | |
| """ | |
| } | |
| def format_results(report: Dict, images: List[str], scores: Dict) -> Dict: | |
| """Format successful results for display""" | |
| try: | |
| # Format main results | |
| markdown_content = f""" | |
| ### π Analysis Results | |
| #### Query Analysis | |
| {report.get('query_analysis', 'No analysis available')} | |
| #### Key Findings | |
| {report.get('key_findings', 'No findings available')} | |
| #### Recommendations | |
| {report.get('recommendations', 'No recommendations available')} | |
| """ | |
| # Format confidence scores | |
| confidence_display = { | |
| 'Model Performance': scores.get('model_decisions', {}), | |
| 'Overall Confidence': f"{scores.get('average_confidence', 0) * 100:.1f}%" | |
| } | |
| return { | |
| 'status': 'success', | |
| 'content': markdown_content, | |
| 'scores': confidence_display, | |
| 'images': images | |
| } | |
| except Exception as e: | |
| return DisplayFormatter.format_error(f"Error formatting results: {str(e)}") | |
| formatter = DisplayFormatter() | |
| format_results = formatter.format_results | |
| format_error = formatter.format_error |