Spaces:
Running
Running
File size: 5,671 Bytes
ce6a24b |
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
"""
Analytics & SEO Module for ProVerBs Ultimate Brain
- Google Analytics integration
- Query tracking
- User behavior analytics
- SEO optimization
"""
import json
from datetime import datetime
from typing import Dict, List, Optional
import logging
logger = logging.getLogger(__name__)
class AnalyticsTracker:
"""Track user queries and interactions"""
def __init__(self):
self.queries: List[Dict] = []
self.sessions: Dict[str, Dict] = {}
self.popular_modes: Dict[str, int] = {}
self.popular_ai_models: Dict[str, int] = {}
def track_query(
self,
query: str,
mode: str,
ai_provider: str,
reasoning_enabled: bool,
response_time: float,
success: bool
):
"""Track a query"""
entry = {
"timestamp": datetime.now().isoformat(),
"query": query[:100], # Truncate for privacy
"mode": mode,
"ai_provider": ai_provider,
"reasoning_enabled": reasoning_enabled,
"response_time": response_time,
"success": success
}
self.queries.append(entry)
# Track mode popularity
self.popular_modes[mode] = self.popular_modes.get(mode, 0) + 1
# Track AI model popularity
self.popular_ai_models[ai_provider] = self.popular_ai_models.get(ai_provider, 0) + 1
logger.info(f"Tracked query: {query[:50]}... [Mode: {mode}, AI: {ai_provider}]")
def get_analytics(self) -> Dict:
"""Get analytics summary"""
total_queries = len(self.queries)
successful_queries = sum(1 for q in self.queries if q['success'])
avg_response_time = sum(q['response_time'] for q in self.queries) / total_queries if total_queries > 0 else 0
# Get top modes
top_modes = sorted(self.popular_modes.items(), key=lambda x: x[1], reverse=True)[:3]
# Get top AI models
top_ai = sorted(self.popular_ai_models.items(), key=lambda x: x[1], reverse=True)[:3]
return {
"total_queries": total_queries,
"successful_queries": successful_queries,
"success_rate": f"{(successful_queries/total_queries*100):.2f}%" if total_queries > 0 else "0%",
"avg_response_time": f"{avg_response_time:.2f}s",
"top_modes": top_modes,
"top_ai_models": top_ai,
"queries_with_reasoning": sum(1 for q in self.queries if q['reasoning_enabled']),
"recent_queries": self.queries[-10:][::-1] # Last 10, reversed
}
def export_analytics(self, filepath: str = "analytics_data.json"):
"""Export analytics to JSON file"""
data = self.get_analytics()
with open(filepath, 'w') as f:
json.dump(data, f, indent=2)
logger.info(f"Analytics exported to {filepath}")
class SEOOptimizer:
"""SEO optimization utilities"""
@staticmethod
def get_meta_tags() -> str:
"""Generate SEO meta tags"""
return """
<meta name="description" content="ProVerBs Ultimate Legal AI Brain - Advanced legal assistant with 100+ reasoning protocols, multi-AI support, and specialized legal modes. Free to use.">
<meta name="keywords" content="legal AI, legal assistant, chain of thought, reasoning AI, legal research, document validation, ProVerBs, ADAPPT-I, quantum reasoning">
<meta name="author" content="Solomon7890">
<meta name="robots" content="index, follow">
<meta property="og:title" content="ProVerBs Ultimate Legal AI Brain">
<meta property="og:description" content="The most advanced legal AI platform with 100+ reasoning protocols and multi-AI support">
<meta property="og:type" content="website">
<meta property="og:url" content="https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE">
<meta property="og:image" content="https://huggingface.co/spaces/Solomon7890/ProVerbS_LaW_mAiN_PAgE/resolve/main/preview.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="ProVerBs Ultimate Legal AI Brain">
<meta name="twitter:description" content="Advanced legal AI with 100+ reasoning protocols">
"""
@staticmethod
def get_structured_data() -> str:
"""Generate JSON-LD structured data for SEO"""
return """
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "ProVerBs Ultimate Legal AI Brain",
"description": "Advanced legal AI assistant with 100+ reasoning protocols, multi-AI support, and specialized legal modes",
"applicationCategory": "LegalTechnology",
"operatingSystem": "Web Browser",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
},
"author": {
"@type": "Person",
"name": "Solomon7890"
},
"featureList": [
"100+ Reasoning Protocols",
"6 AI Models (GPT-4, Gemini, Perplexity, etc.)",
"7 Specialized Legal Modes",
"Chain-of-Thought Reasoning",
"Document Validation",
"Legal Research Assistant"
]
}
</script>
"""
# Global analytics tracker
analytics_tracker = AnalyticsTracker()
|