petter2025 commited on
Commit
e327855
Β·
verified Β·
1 Parent(s): 7f5a7ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -101
app.py CHANGED
@@ -13,13 +13,6 @@ CRITICAL FIXES APPLIED:
13
  - Rate limiting
14
  - Comprehensive input validation
15
  - Circuit breakers for agent resilience
16
-
17
- ENHANCEMENTS FOR FIRST-TIME USERS:
18
- - First-time user detection and welcome experience
19
- - Enhanced empty states with guidance
20
- - Progressive disclosure of advanced features
21
- - Improved demo scenario discovery
22
- - Real-time slider feedback with threshold indicators
23
  """
24
 
25
  import os
@@ -41,7 +34,6 @@ from concurrent.futures import ProcessPoolExecutor
41
  from queue import Queue
42
  from circuitbreaker import circuit
43
  import atomicwrites
44
- from pathlib import Path
45
 
46
  # Import our modules
47
  from models import (
@@ -59,27 +51,6 @@ logger = logging.getLogger(__name__)
59
 
60
 
61
 
62
- # === First-Time User Detection ===
63
- FIRST_TIME_FILE = Path(".arf_first_time_user.json")
64
-
65
- def is_first_time_user():
66
- """Check if this is the user's first visit"""
67
- if not FIRST_TIME_FILE.exists():
68
- return True
69
- try:
70
- with open(FIRST_TIME_FILE, 'r') as f:
71
- data = json.load(f)
72
- return data.get('first_time', True)
73
- except:
74
- return True
75
-
76
- def mark_user_visited():
77
- """Mark that user has visited (call after first interaction)"""
78
- data = {'first_time': False, 'first_visit_date': str(datetime.datetime.now())}
79
- with open(FIRST_TIME_FILE, 'w') as f:
80
- json.dump(data, f)
81
-
82
-
83
  # === CONSTANTS (FIXED: Extracted all magic numbers) ===
84
  class Constants:
85
  """Centralized constants to eliminate magic numbers"""
@@ -580,6 +551,10 @@ try:
580
  from sentence_transformers import SentenceTransformer
581
  import faiss
582
 
 
 
 
 
583
  if os.path.exists(config.INDEX_FILE):
584
  logger.info(f"Loading existing FAISS index from {config.INDEX_FILE}")
585
  index = faiss.read_index(config.INDEX_FILE)
@@ -1839,7 +1814,6 @@ def create_enhanced_ui():
1839
  FIXED: Rate limiting on all endpoints
1840
  NEW: Demo scenarios for killer presentations
1841
  NEW: ROI Dashboard with real-time business metrics
1842
- ENHANCED: First-time user experience with guided onboarding
1843
  """
1844
 
1845
  with gr.Blocks(title="🧠 Agentic Reliability Framework", theme="soft") as demo:
@@ -1853,27 +1827,6 @@ def create_enhanced_ui():
1853
 
1854
  # === ROI DASHBOARD ===
1855
  with gr.Accordion("πŸ’° Business Impact Dashboard", open=True):
1856
- # Check if first-time user
1857
- first_time = is_first_time_user()
1858
-
1859
- # Welcome banner for first-time users
1860
- if first_time:
1861
- gr.Markdown("""
1862
- <div style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
1863
- padding: 20px; border-radius: 10px; color: white; margin-bottom: 20px;'>
1864
- <h3 style='margin-top: 0;'>πŸš€ Welcome to ARF! Your First Analysis Awaits</h3>
1865
- <p><strong>Get started in 30 seconds:</strong></p>
1866
- <ol style='margin-bottom: 0;'>
1867
- <li>Select a <strong>Demo Scenario</strong> below (try "πŸ›οΈ Black Friday Crisis")</li>
1868
- <li>Click <strong>πŸš€ Submit Telemetry Event</strong></li>
1869
- <li>Watch AI agents diagnose the issue in real-time</li>
1870
- </ol>
1871
- <p style='margin-top: 10px; font-size: 0.9em; opacity: 0.9;'>
1872
- ⭐ <em>82% of users discover critical issues in their first demo</em>
1873
- </p>
1874
- </div>
1875
- """)
1876
-
1877
  gr.Markdown("""
1878
  ### Real-Time ROI Metrics
1879
  Track cumulative business value delivered by ARF across all analyzed incidents.
@@ -1884,23 +1837,20 @@ def create_enhanced_ui():
1884
  total_incidents_display = gr.Number(
1885
  label="πŸ“Š Total Incidents Analyzed",
1886
  value=0,
1887
- interactive=False,
1888
- info="Submit your first telemetry to see analysis" if first_time else None
1889
  )
1890
  with gr.Column(scale=1):
1891
  incidents_healed_display = gr.Number(
1892
  label="πŸ”§ Incidents Auto-Healed",
1893
  value=0,
1894
- interactive=False,
1895
- info="AI-powered healing triggers after analysis" if first_time else None
1896
  )
1897
  with gr.Column(scale=1):
1898
  auto_heal_rate_display = gr.Number(
1899
  label="⚑ Auto-Heal Rate (%)",
1900
  value=0,
1901
  interactive=False,
1902
- precision=1,
1903
- info="Percentage of incidents resolved automatically" if first_time else None
1904
  )
1905
 
1906
  with gr.Row():
@@ -1909,24 +1859,21 @@ def create_enhanced_ui():
1909
  label="πŸ’° Revenue Saved (\$)",
1910
  value=0,
1911
  interactive=False,
1912
- precision=2,
1913
- info="Potential cost savings from faster resolution" if first_time else None
1914
  )
1915
  with gr.Column(scale=1):
1916
  avg_detection_display = gr.Number(
1917
  label="⏱️ Avg Detection Time (min)",
1918
  value=2.3,
1919
  interactive=False,
1920
- precision=1,
1921
- info="Average time to detect incidents" if first_time else None
1922
  )
1923
  with gr.Column(scale=1):
1924
  time_improvement_display = gr.Number(
1925
  label="πŸš€ Time Improvement vs Industry (%)",
1926
  value=83.6,
1927
  interactive=False,
1928
- precision=1,
1929
- info="How much faster than industry average" if first_time else None
1930
  )
1931
 
1932
  with gr.Row():
@@ -1946,39 +1893,21 @@ def create_enhanced_ui():
1946
  with gr.Column(scale=1):
1947
  gr.Markdown("### πŸ“Š Telemetry Input")
1948
 
1949
- # Enhanced Demo Scenarios Section
1950
- gr.Markdown("### 🎬 Quick Start Demo Scenarios")
1951
- first_time = is_first_time_user()
1952
-
1953
  with gr.Row():
1954
  scenario_dropdown = gr.Dropdown(
1955
- choices=["Select a scenario..."] + list(DEMO_SCENARIOS.keys()),
1956
- value="Select a scenario..." if first_time else "Manual Entry",
1957
- label="Demo Scenario Selector",
1958
- info="🎯 **Recommended for first-time users:** Try 'πŸ›οΈ Black Friday Crisis'"
1959
  )
1960
 
1961
- # Scenario descriptions that appear when selected
1962
  scenario_story = gr.Markdown(
1963
- value="" if first_time else "πŸ’‘ *Select a scenario above to pre-fill realistic telemetry values*",
1964
  visible=True
1965
  )
1966
 
1967
- # Quick scenario cards (visual alternative for first-time users)
1968
- if first_time:
1969
- gr.Markdown("""
1970
- <div style='display: flex; gap: 10px; margin-top: 15px;'>
1971
- <div style='flex: 1; padding: 15px; background: #f0f7ff; border-radius: 8px; border-left: 4px solid #667eea; cursor: pointer;' onclick='document.querySelector("select[data-testid]").value = "πŸ›οΈ Black Friday Crisis"; document.querySelector("select[data-testid]").dispatchEvent(new Event("change"));'>
1972
- <strong>πŸ›οΈ Black Friday Crisis</strong><br>
1973
- <small>Payment failing during peak traffic</small>
1974
- </div>
1975
- <div style='flex: 1; padding: 15px; background: #fff0f0; border-radius: 8px; border-left: 4px solid #e53e3e; cursor: pointer;' onclick='document.querySelector("select[data-testid]").value = "🚨 Database Meltdown"; document.querySelector("select[data-testid]").dispatchEvent(new Event("change"));'>
1976
- <strong>🚨 Database Meltdown</strong><br>
1977
- <small>Cascading failures across services</small>
1978
- </div>
1979
- </div>
1980
- """)
1981
-
1982
  component = gr.Dropdown(
1983
  choices=["api-service", "auth-service", "payment-service", "database", "cache-service"],
1984
  value="api-service",
@@ -1988,12 +1917,12 @@ def create_enhanced_ui():
1988
  latency = gr.Slider(
1989
  minimum=10, maximum=1000, value=100, step=1,
1990
  label="Latency P99 (ms)",
1991
- info=f"Alert threshold: >{Constants.LATENCY_WARNING}ms (🟒 Normal: <150ms, 🟑 Warning: 150-300ms, πŸ”΄ Critical: >300ms)"
1992
  )
1993
  error_rate = gr.Slider(
1994
  minimum=0, maximum=0.5, value=0.02, step=0.001,
1995
  label="Error Rate",
1996
- info=f"Alert threshold: >{Constants.ERROR_RATE_WARNING} (🟒 Normal: <5%, 🟑 Warning: 5-15%, πŸ”΄ Critical: >15%)"
1997
  )
1998
  throughput = gr.Number(
1999
  value=1000,
@@ -2003,12 +1932,12 @@ def create_enhanced_ui():
2003
  cpu_util = gr.Slider(
2004
  minimum=0, maximum=1, value=0.4, step=0.01,
2005
  label="CPU Utilization",
2006
- info="0.0 - 1.0 scale (🟒 Normal: <80%, 🟑 Warning: 80-90%, πŸ”΄ Critical: >90%)"
2007
  )
2008
  memory_util = gr.Slider(
2009
  minimum=0, maximum=1, value=0.3, step=0.01,
2010
  label="Memory Utilization",
2011
- info="0.0 - 1.0 scale (🟒 Normal: <80%, 🟑 Warning: 80-90%, πŸ”΄ Critical: >90%)"
2012
  )
2013
  submit_btn = gr.Button("πŸš€ Submit Telemetry Event", variant="primary", size="lg")
2014
 
@@ -2082,9 +2011,9 @@ def create_enhanced_ui():
2082
  # Scenario change handler
2083
  def on_scenario_change(scenario_name):
2084
  """Update input fields when demo scenario is selected"""
2085
- if scenario_name == "Select a scenario..." or scenario_name == "Manual Entry":
2086
  return {
2087
- scenario_story: gr.update(value="*Enter values manually below, or select a demo scenario for a realistic example.*"),
2088
  component: gr.update(value="api-service"),
2089
  latency: gr.update(value=100),
2090
  error_rate: gr.update(value=0.02),
@@ -2144,12 +2073,7 @@ def create_enhanced_ui():
2144
  FIXED: Rate limiting added
2145
  FIXED: Comprehensive error handling
2146
  NEW: Updates ROI dashboard metrics
2147
- ENHANCED: First-time user tracking
2148
  """
2149
- # Mark user as no longer first-time (if they are)
2150
- if is_first_time_user():
2151
- mark_user_visited()
2152
-
2153
  try:
2154
  # Rate limiting check
2155
  allowed, rate_msg = rate_limiter.is_allowed()
@@ -2325,7 +2249,7 @@ def create_enhanced_ui():
2325
  # === Main Entry Point ===
2326
  if __name__ == "__main__":
2327
  logger.info("=" * 80)
2328
- logger.info("Starting Enterprise Agentic Reliability Framework (ENHANCED FIRST-TIME UX)")
2329
  logger.info("=" * 80)
2330
  logger.info(f"Python version: {os.sys.version}")
2331
  logger.info(f"Total events in history: {enhanced_engine.event_store.count()}")
@@ -2335,7 +2259,6 @@ if __name__ == "__main__":
2335
  logger.info(f"Demo scenarios loaded: {len(DEMO_SCENARIOS)}")
2336
  logger.info(f"Configuration: HF_TOKEN={'SET' if config.HF_TOKEN else 'NOT SET'}")
2337
  logger.info(f"Rate limit: {Constants.MAX_REQUESTS_PER_MINUTE} requests/minute")
2338
- logger.info(f"First-time user: {is_first_time_user()}")
2339
  logger.info("=" * 80)
2340
 
2341
  try:
 
13
  - Rate limiting
14
  - Comprehensive input validation
15
  - Circuit breakers for agent resilience
 
 
 
 
 
 
 
16
  """
17
 
18
  import os
 
34
  from queue import Queue
35
  from circuitbreaker import circuit
36
  import atomicwrites
 
37
 
38
  # Import our modules
39
  from models import (
 
51
 
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  # === CONSTANTS (FIXED: Extracted all magic numbers) ===
55
  class Constants:
56
  """Centralized constants to eliminate magic numbers"""
 
551
  from sentence_transformers import SentenceTransformer
552
  import faiss
553
 
554
+ # REMOVED: logger.info("Loading SentenceTransformer model...")
555
+ # REMOVED: model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
556
+ # REMOVED: logger.info("SentenceTransformer model loaded successfully")
557
+
558
  if os.path.exists(config.INDEX_FILE):
559
  logger.info(f"Loading existing FAISS index from {config.INDEX_FILE}")
560
  index = faiss.read_index(config.INDEX_FILE)
 
1814
  FIXED: Rate limiting on all endpoints
1815
  NEW: Demo scenarios for killer presentations
1816
  NEW: ROI Dashboard with real-time business metrics
 
1817
  """
1818
 
1819
  with gr.Blocks(title="🧠 Agentic Reliability Framework", theme="soft") as demo:
 
1827
 
1828
  # === ROI DASHBOARD ===
1829
  with gr.Accordion("πŸ’° Business Impact Dashboard", open=True):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1830
  gr.Markdown("""
1831
  ### Real-Time ROI Metrics
1832
  Track cumulative business value delivered by ARF across all analyzed incidents.
 
1837
  total_incidents_display = gr.Number(
1838
  label="πŸ“Š Total Incidents Analyzed",
1839
  value=0,
1840
+ interactive=False
 
1841
  )
1842
  with gr.Column(scale=1):
1843
  incidents_healed_display = gr.Number(
1844
  label="πŸ”§ Incidents Auto-Healed",
1845
  value=0,
1846
+ interactive=False
 
1847
  )
1848
  with gr.Column(scale=1):
1849
  auto_heal_rate_display = gr.Number(
1850
  label="⚑ Auto-Heal Rate (%)",
1851
  value=0,
1852
  interactive=False,
1853
+ precision=1
 
1854
  )
1855
 
1856
  with gr.Row():
 
1859
  label="πŸ’° Revenue Saved (\$)",
1860
  value=0,
1861
  interactive=False,
1862
+ precision=2
 
1863
  )
1864
  with gr.Column(scale=1):
1865
  avg_detection_display = gr.Number(
1866
  label="⏱️ Avg Detection Time (min)",
1867
  value=2.3,
1868
  interactive=False,
1869
+ precision=1
 
1870
  )
1871
  with gr.Column(scale=1):
1872
  time_improvement_display = gr.Number(
1873
  label="πŸš€ Time Improvement vs Industry (%)",
1874
  value=83.6,
1875
  interactive=False,
1876
+ precision=1
 
1877
  )
1878
 
1879
  with gr.Row():
 
1893
  with gr.Column(scale=1):
1894
  gr.Markdown("### πŸ“Š Telemetry Input")
1895
 
1896
+ # Demo Scenarios Dropdown
 
 
 
1897
  with gr.Row():
1898
  scenario_dropdown = gr.Dropdown(
1899
+ choices=["Manual Entry"] + list(DEMO_SCENARIOS.keys()),
1900
+ value="Manual Entry",
1901
+ label="🎬 Demo Scenario (Quick Start)",
1902
+ info="Select a pre-configured scenario or enter manually"
1903
  )
1904
 
1905
+ # Scenario Story Display
1906
  scenario_story = gr.Markdown(
1907
+ value="*Select a demo scenario above for a pre-configured incident, or enter values manually below.*",
1908
  visible=True
1909
  )
1910
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1911
  component = gr.Dropdown(
1912
  choices=["api-service", "auth-service", "payment-service", "database", "cache-service"],
1913
  value="api-service",
 
1917
  latency = gr.Slider(
1918
  minimum=10, maximum=1000, value=100, step=1,
1919
  label="Latency P99 (ms)",
1920
+ info=f"Alert threshold: >{Constants.LATENCY_WARNING}ms (adaptive)"
1921
  )
1922
  error_rate = gr.Slider(
1923
  minimum=0, maximum=0.5, value=0.02, step=0.001,
1924
  label="Error Rate",
1925
+ info=f"Alert threshold: >{Constants.ERROR_RATE_WARNING}"
1926
  )
1927
  throughput = gr.Number(
1928
  value=1000,
 
1932
  cpu_util = gr.Slider(
1933
  minimum=0, maximum=1, value=0.4, step=0.01,
1934
  label="CPU Utilization",
1935
+ info="0.0 - 1.0 scale"
1936
  )
1937
  memory_util = gr.Slider(
1938
  minimum=0, maximum=1, value=0.3, step=0.01,
1939
  label="Memory Utilization",
1940
+ info="0.0 - 1.0 scale"
1941
  )
1942
  submit_btn = gr.Button("πŸš€ Submit Telemetry Event", variant="primary", size="lg")
1943
 
 
2011
  # Scenario change handler
2012
  def on_scenario_change(scenario_name):
2013
  """Update input fields when demo scenario is selected"""
2014
+ if scenario_name == "Manual Entry":
2015
  return {
2016
+ scenario_story: gr.update(value="*Enter values manually below.*"),
2017
  component: gr.update(value="api-service"),
2018
  latency: gr.update(value=100),
2019
  error_rate: gr.update(value=0.02),
 
2073
  FIXED: Rate limiting added
2074
  FIXED: Comprehensive error handling
2075
  NEW: Updates ROI dashboard metrics
 
2076
  """
 
 
 
 
2077
  try:
2078
  # Rate limiting check
2079
  allowed, rate_msg = rate_limiter.is_allowed()
 
2249
  # === Main Entry Point ===
2250
  if __name__ == "__main__":
2251
  logger.info("=" * 80)
2252
+ logger.info("Starting Enterprise Agentic Reliability Framework (DEMO READY VERSION)")
2253
  logger.info("=" * 80)
2254
  logger.info(f"Python version: {os.sys.version}")
2255
  logger.info(f"Total events in history: {enhanced_engine.event_store.count()}")
 
2259
  logger.info(f"Demo scenarios loaded: {len(DEMO_SCENARIOS)}")
2260
  logger.info(f"Configuration: HF_TOKEN={'SET' if config.HF_TOKEN else 'NOT SET'}")
2261
  logger.info(f"Rate limit: {Constants.MAX_REQUESTS_PER_MINUTE} requests/minute")
 
2262
  logger.info("=" * 80)
2263
 
2264
  try: