Spaces:
Sleeping
Sleeping
File size: 4,851 Bytes
6f38c76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
"""
Extension methods for RegressionTestingApp
Adds HF Vision and Storage management methods
"""
from storage_manager import get_storage_manager
def get_hf_analysis_info(app_instance) -> str:
"""Get HF Vision analysis results."""
if not app_instance.current_state or not hasattr(app_instance.current_state, 'hf_analysis_results'):
return "No HF analysis results available yet. Run a test to see results."
hf_results = app_instance.current_state.hf_analysis_results
if not hf_results:
return "HF Vision analysis not performed (model not available or disabled)."
lines = []
lines.append("# HF Vision Model Analysis Results\n")
for viewport, result in hf_results.items():
lines.append(f"## {viewport.upper()} Viewport\n")
if "error" in result:
lines.append(f"Error: {result['error']}\n")
continue
comp_type = result.get("comparison_type", "unknown")
if comp_type == "captioning":
lines.append(f"**Analysis Type**: Image Captioning\n")
lines.append(f"**Design Caption**: {result.get('figma_caption', 'N/A')}")
lines.append(f"**Website Caption**: {result.get('website_caption', 'N/A')}")
lines.append(f"**Similarity Score**: {result.get('similarity_score', 0):.1f}%\n")
if result.get("missing_elements"):
lines.append(f"**Missing Elements**: {', '.join(result['missing_elements'])}")
if result.get("extra_elements"):
lines.append(f"**Extra Elements**: {', '.join(result['extra_elements'])}\n")
elif comp_type == "detection":
lines.append(f"**Analysis Type**: Object Detection\n")
lines.append(f"**Design Objects**: {result.get('figma_object_count', 0)}")
lines.append(f"**Website Objects**: {result.get('website_object_count', 0)}\n")
if result.get("missing_objects"):
lines.append(f"**Missing Objects**: {', '.join(result['missing_objects'])}")
if result.get("extra_objects"):
lines.append(f"**Extra Objects**: {', '.join(result['extra_objects'])}\n")
return "\n".join(lines) if lines else "No HF analysis results available."
def get_storage_info(app_instance) -> str:
"""Get storage information."""
try:
storage = get_storage_manager()
stats = storage.get_storage_stats()
executions = storage.list_executions()
lines = []
lines.append("# Screenshot Storage Information\n")
# Overall stats
lines.append("## Storage Statistics\n")
lines.append(f"- **Total Files**: {stats.get('total_files', 0)}")
lines.append(f"- **Total Size**: {stats.get('total_size_mb', 0):.2f}MB")
lines.append(f"- **Storage Location**: {stats.get('base_dir', 'N/A')}\n")
# Recent executions
if executions:
lines.append("## Recent Executions\n")
for exec_info in executions[:10]: # Show last 10
lines.append(f"### {exec_info['execution_id']}")
lines.append(f"- **Timestamp**: {exec_info['timestamp']}")
lines.append(f"- **Screenshots**: {exec_info['screenshot_count']}")
lines.append(f"- **Size**: {exec_info['size_mb']:.2f}MB\n")
else:
lines.append("No executions stored yet.\n")
# Storage recommendations
lines.append("## Storage Management\n")
lines.append("- Screenshots are automatically saved for each test run")
lines.append("- Old screenshots (7+ days) can be cleaned up using the cleanup button")
lines.append(f"- Current storage: {stats.get('total_size_mb', 0):.2f}MB")
return "\n".join(lines)
except Exception as e:
return f"Error getting storage info: {str(e)}"
def cleanup_storage(app_instance) -> str:
"""Cleanup old screenshots."""
try:
storage = get_storage_manager()
deleted_count, freed_space = storage.cleanup_old_screenshots(days=7)
lines = []
lines.append("# Storage Cleanup Results\n")
lines.append(f"Cleanup completed successfully!\n")
lines.append(f"- **Files Deleted**: {deleted_count}")
lines.append(f"- **Space Freed**: {freed_space:.2f}MB\n")
# Show updated stats
stats = storage.get_storage_stats()
lines.append("## Updated Storage Statistics\n")
lines.append(f"- **Total Files**: {stats.get('total_files', 0)}")
lines.append(f"- **Total Size**: {stats.get('total_size_mb', 0):.2f}MB")
return "\n".join(lines)
except Exception as e:
return f"Error during cleanup: {str(e)}"
|