Solomon7890 commited on
Commit
36c80e0
·
verified ·
1 Parent(s): c651efa

🧠 Ultimate Brain v3.0: Multi-AI + 100+ Reasoning Protocols + Supertonic

Browse files
Files changed (1) hide show
  1. app.py +95 -0
app.py CHANGED
@@ -16,6 +16,10 @@ import requests
16
  # Import Unified Brain
17
  from unified_brain import UnifiedBrain, ReasoningContext
18
 
 
 
 
 
19
  class UltimateLegalBrain:
20
  """
21
  Ultimate Legal AI Brain combining:
@@ -103,6 +107,19 @@ async def respond_with_ultimate_brain(
103
  ):
104
  """Generate response using Ultimate Brain"""
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  # Process with Brain
107
  brain_result = await ultimate_brain.process_legal_query(
108
  query=message,
@@ -198,7 +215,15 @@ custom_css = """
198
  # Create Gradio Interface
199
  demo = gr.Blocks(title="ProVerBs Ultimate Legal AI Brain", css=custom_css)
200
 
 
 
 
 
201
  with demo:
 
 
 
 
202
  gr.HTML("""
203
  <div class="header-section">
204
  <h1>⚖️ ProVerBs Ultimate Legal AI Brain</h1>
@@ -417,6 +442,76 @@ with demo:
417
  - Regulatory updates with RAG
418
  """)
419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  # About Tab
421
  with gr.Tab("ℹ️ About"):
422
  gr.Markdown("""
 
16
  # Import Unified Brain
17
  from unified_brain import UnifiedBrain, ReasoningContext
18
 
19
+ # Import Performance & Analytics
20
+ from performance_optimizer import performance_cache, performance_monitor, with_caching
21
+ from analytics_seo import analytics_tracker, SEOOptimizer
22
+
23
  class UltimateLegalBrain:
24
  """
25
  Ultimate Legal AI Brain combining:
 
107
  ):
108
  """Generate response using Ultimate Brain"""
109
 
110
+ import time
111
+ start_time = time.time()
112
+
113
+ # Track analytics
114
+ analytics_tracker.track_query(
115
+ query=message,
116
+ mode=mode,
117
+ ai_provider=ai_provider,
118
+ reasoning_enabled=use_reasoning,
119
+ response_time=0, # Will update later
120
+ success=True
121
+ )
122
+
123
  # Process with Brain
124
  brain_result = await ultimate_brain.process_legal_query(
125
  query=message,
 
215
  # Create Gradio Interface
216
  demo = gr.Blocks(title="ProVerBs Ultimate Legal AI Brain", css=custom_css)
217
 
218
+ # Add SEO meta tags
219
+ seo_meta = SEOOptimizer.get_meta_tags()
220
+ seo_structured = SEOOptimizer.get_structured_data()
221
+
222
  with demo:
223
+ # Add SEO tags
224
+ gr.HTML(seo_meta + seo_structured)
225
+
226
+ # Header
227
  gr.HTML("""
228
  <div class="header-section">
229
  <h1>⚖️ ProVerBs Ultimate Legal AI Brain</h1>
 
442
  - Regulatory updates with RAG
443
  """)
444
 
445
+ # Analytics Dashboard Tab
446
+ with gr.Tab("📊 Analytics"):
447
+ gr.Markdown("""
448
+ ## Analytics & Performance Dashboard
449
+
450
+ View real-time analytics and performance metrics for the Ultimate Brain.
451
+ """)
452
+
453
+ with gr.Row():
454
+ analytics_btn = gr.Button("📊 Refresh Analytics", variant="primary")
455
+ clear_cache_btn = gr.Button("🗑️ Clear Cache", variant="secondary")
456
+
457
+ analytics_output = gr.JSON(label="Analytics Data")
458
+ performance_output = gr.JSON(label="Performance Metrics")
459
+ cache_stats_output = gr.JSON(label="Cache Statistics")
460
+
461
+ def get_analytics():
462
+ return analytics_tracker.get_analytics()
463
+
464
+ def get_performance():
465
+ return performance_monitor.get_metrics()
466
+
467
+ def get_cache_stats():
468
+ return performance_cache.get_stats()
469
+
470
+ def clear_cache_action():
471
+ performance_cache.clear()
472
+ return {"status": "Cache cleared successfully"}
473
+
474
+ analytics_btn.click(
475
+ fn=lambda: (get_analytics(), get_performance(), get_cache_stats()),
476
+ outputs=[analytics_output, performance_output, cache_stats_output]
477
+ )
478
+
479
+ clear_cache_btn.click(
480
+ fn=clear_cache_action,
481
+ outputs=[cache_stats_output]
482
+ )
483
+
484
+ gr.Markdown("""
485
+ ### 📈 What's Tracked:
486
+
487
+ **Analytics:**
488
+ - Total queries processed
489
+ - Success rate
490
+ - Average response time
491
+ - Most popular legal modes
492
+ - Most popular AI models
493
+ - Reasoning protocol usage
494
+ - Recent queries
495
+
496
+ **Performance:**
497
+ - Cache hit rate
498
+ - Total requests
499
+ - Average response time
500
+ - Error rate
501
+
502
+ **Cache:**
503
+ - Current cache size
504
+ - Maximum capacity
505
+ - TTL (Time To Live)
506
+ - Oldest cached entry
507
+
508
+ ### 💡 Optimization Tips:
509
+ - High cache hit rate = faster responses
510
+ - Monitor popular modes to optimize
511
+ - Clear cache if experiencing issues
512
+ - Analytics help identify usage patterns
513
+ """)
514
+
515
  # About Tab
516
  with gr.Tab("ℹ️ About"):
517
  gr.Markdown("""