Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
from config import config
|
| 2 |
-
from config import config
|
| 3 |
"""
|
| 4 |
Enterprise Agentic Reliability Framework - Main Application (FIXED VERSION)
|
| 5 |
Multi-Agent AI System for Production Reliability Monitoring
|
|
@@ -551,10 +550,6 @@ try:
|
|
| 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)
|
|
@@ -590,7 +585,7 @@ except Exception as e:
|
|
| 590 |
model = None
|
| 591 |
thread_safe_index = None
|
| 592 |
|
| 593 |
-
|
| 594 |
class SimplePredictiveEngine:
|
| 595 |
"""
|
| 596 |
Lightweight forecasting engine with proper constant usage
|
|
@@ -929,7 +924,7 @@ class BusinessImpactCalculator:
|
|
| 929 |
severity = "LOW"
|
| 930 |
|
| 931 |
logger.info(
|
| 932 |
-
f"Business impact: \{revenue_loss:.2f} revenue loss, "
|
| 933 |
f"{affected_users} users, {severity} severity"
|
| 934 |
)
|
| 935 |
|
|
@@ -988,7 +983,7 @@ class AdvancedAnomalyDetector:
|
|
| 988 |
self.adaptive_thresholds['latency_p99'] = new_threshold
|
| 989 |
logger.debug(f"Updated adaptive latency threshold to {new_threshold:.2f}ms")
|
| 990 |
|
| 991 |
-
|
| 992 |
class AgentSpecialization(Enum):
|
| 993 |
"""Agent specialization types"""
|
| 994 |
DETECTIVE = "anomaly_detection"
|
|
@@ -1515,7 +1510,7 @@ class OrchestrationManager:
|
|
| 1515 |
unique_actions.append(action)
|
| 1516 |
return unique_actions[:5]
|
| 1517 |
|
| 1518 |
-
|
| 1519 |
class EnhancedReliabilityEngine:
|
| 1520 |
"""
|
| 1521 |
Main engine for processing reliability events
|
|
@@ -2080,7 +2075,8 @@ def create_enhanced_ui():
|
|
| 2080 |
if not allowed:
|
| 2081 |
logger.warning(f"Rate limit exceeded")
|
| 2082 |
metrics = business_metrics.get_metrics()
|
| 2083 |
-
return (
|
|
|
|
| 2084 |
metrics["total_incidents"],
|
| 2085 |
metrics["incidents_auto_healed"],
|
| 2086 |
metrics["auto_heal_rate"],
|
|
@@ -2100,7 +2096,8 @@ def create_enhanced_ui():
|
|
| 2100 |
error_msg = f"❌ Invalid input types: {str(e)}"
|
| 2101 |
logger.warning(error_msg)
|
| 2102 |
metrics = business_metrics.get_metrics()
|
| 2103 |
-
return (
|
|
|
|
| 2104 |
metrics["total_incidents"],
|
| 2105 |
metrics["incidents_auto_healed"],
|
| 2106 |
metrics["auto_heal_rate"],
|
|
@@ -2116,7 +2113,8 @@ def create_enhanced_ui():
|
|
| 2116 |
if not is_valid:
|
| 2117 |
logger.warning(f"Invalid input: {error_msg}")
|
| 2118 |
metrics = business_metrics.get_metrics()
|
| 2119 |
-
return (
|
|
|
|
| 2120 |
metrics["total_incidents"],
|
| 2121 |
metrics["incidents_auto_healed"],
|
| 2122 |
metrics["auto_heal_rate"],
|
|
@@ -2133,7 +2131,8 @@ def create_enhanced_ui():
|
|
| 2133 |
# Handle errors
|
| 2134 |
if 'error' in result:
|
| 2135 |
metrics = business_metrics.get_metrics()
|
| 2136 |
-
return (
|
|
|
|
| 2137 |
metrics["total_incidents"],
|
| 2138 |
metrics["incidents_auto_healed"],
|
| 2139 |
metrics["auto_heal_rate"],
|
|
@@ -2195,7 +2194,7 @@ def create_enhanced_ui():
|
|
| 2195 |
output_msg,
|
| 2196 |
agent_insights_data,
|
| 2197 |
predictive_insights_data,
|
| 2198 |
-
gr.update(value=table_data),
|
| 2199 |
metrics["total_incidents"],
|
| 2200 |
metrics["incidents_auto_healed"],
|
| 2201 |
metrics["auto_heal_rate"],
|
|
@@ -2208,7 +2207,8 @@ def create_enhanced_ui():
|
|
| 2208 |
error_msg = f"❌ Error processing event: {str(e)}"
|
| 2209 |
logger.error(error_msg, exc_info=True)
|
| 2210 |
metrics = business_metrics.get_metrics()
|
| 2211 |
-
return (
|
|
|
|
| 2212 |
metrics["total_incidents"],
|
| 2213 |
metrics["incidents_auto_healed"],
|
| 2214 |
metrics["auto_heal_rate"],
|
|
@@ -2236,8 +2236,11 @@ def create_enhanced_ui():
|
|
| 2236 |
)
|
| 2237 |
|
| 2238 |
return demo
|
| 2239 |
-
|
| 2240 |
-
|
|
|
|
|
|
|
|
|
|
| 2241 |
if __name__ == "__main__":
|
| 2242 |
logger.info("=" * 80)
|
| 2243 |
logger.info("Starting Enterprise Agentic Reliability Framework (DEMO READY VERSION)")
|
|
@@ -2253,8 +2256,6 @@ if __name__ == "__main__":
|
|
| 2253 |
logger.info("=" * 80)
|
| 2254 |
|
| 2255 |
try:
|
| 2256 |
-
demo = create_enhanced_ui()
|
| 2257 |
-
|
| 2258 |
logger.info("Launching Gradio UI on 0.0.0.0:7860...")
|
| 2259 |
demo.launch(
|
| 2260 |
server_name="0.0.0.0",
|
|
|
|
| 1 |
from config import config
|
|
|
|
| 2 |
"""
|
| 3 |
Enterprise Agentic Reliability Framework - Main Application (FIXED VERSION)
|
| 4 |
Multi-Agent AI System for Production Reliability Monitoring
|
|
|
|
| 550 |
from sentence_transformers import SentenceTransformer
|
| 551 |
import faiss
|
| 552 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
if os.path.exists(config.INDEX_FILE):
|
| 554 |
logger.info(f"Loading existing FAISS index from {config.INDEX_FILE}")
|
| 555 |
index = faiss.read_index(config.INDEX_FILE)
|
|
|
|
| 585 |
model = None
|
| 586 |
thread_safe_index = None
|
| 587 |
|
| 588 |
+
# === Predictive Models ===
|
| 589 |
class SimplePredictiveEngine:
|
| 590 |
"""
|
| 591 |
Lightweight forecasting engine with proper constant usage
|
|
|
|
| 924 |
severity = "LOW"
|
| 925 |
|
| 926 |
logger.info(
|
| 927 |
+
f"Business impact: \${revenue_loss:.2f} revenue loss, "
|
| 928 |
f"{affected_users} users, {severity} severity"
|
| 929 |
)
|
| 930 |
|
|
|
|
| 983 |
self.adaptive_thresholds['latency_p99'] = new_threshold
|
| 984 |
logger.debug(f"Updated adaptive latency threshold to {new_threshold:.2f}ms")
|
| 985 |
|
| 986 |
+
# === Multi-Agent System ===
|
| 987 |
class AgentSpecialization(Enum):
|
| 988 |
"""Agent specialization types"""
|
| 989 |
DETECTIVE = "anomaly_detection"
|
|
|
|
| 1510 |
unique_actions.append(action)
|
| 1511 |
return unique_actions[:5]
|
| 1512 |
|
| 1513 |
+
# === Enhanced Reliability Engine ===
|
| 1514 |
class EnhancedReliabilityEngine:
|
| 1515 |
"""
|
| 1516 |
Main engine for processing reliability events
|
|
|
|
| 2075 |
if not allowed:
|
| 2076 |
logger.warning(f"Rate limit exceeded")
|
| 2077 |
metrics = business_metrics.get_metrics()
|
| 2078 |
+
return (
|
| 2079 |
+
rate_msg, {}, {}, gr.update(value=[]),
|
| 2080 |
metrics["total_incidents"],
|
| 2081 |
metrics["incidents_auto_healed"],
|
| 2082 |
metrics["auto_heal_rate"],
|
|
|
|
| 2096 |
error_msg = f"❌ Invalid input types: {str(e)}"
|
| 2097 |
logger.warning(error_msg)
|
| 2098 |
metrics = business_metrics.get_metrics()
|
| 2099 |
+
return (
|
| 2100 |
+
error_msg, {}, {}, gr.update(value=[]),
|
| 2101 |
metrics["total_incidents"],
|
| 2102 |
metrics["incidents_auto_healed"],
|
| 2103 |
metrics["auto_heal_rate"],
|
|
|
|
| 2113 |
if not is_valid:
|
| 2114 |
logger.warning(f"Invalid input: {error_msg}")
|
| 2115 |
metrics = business_metrics.get_metrics()
|
| 2116 |
+
return (
|
| 2117 |
+
error_msg, {}, {}, gr.update(value=[]),
|
| 2118 |
metrics["total_incidents"],
|
| 2119 |
metrics["incidents_auto_healed"],
|
| 2120 |
metrics["auto_heal_rate"],
|
|
|
|
| 2131 |
# Handle errors
|
| 2132 |
if 'error' in result:
|
| 2133 |
metrics = business_metrics.get_metrics()
|
| 2134 |
+
return (
|
| 2135 |
+
f"❌ {result['error']}", {}, {}, gr.update(value=[]),
|
| 2136 |
metrics["total_incidents"],
|
| 2137 |
metrics["incidents_auto_healed"],
|
| 2138 |
metrics["auto_heal_rate"],
|
|
|
|
| 2194 |
output_msg,
|
| 2195 |
agent_insights_data,
|
| 2196 |
predictive_insights_data,
|
| 2197 |
+
gr.update(value=table_data), # FIXED: Using gr.update() instead of gr.Dataframe()
|
| 2198 |
metrics["total_incidents"],
|
| 2199 |
metrics["incidents_auto_healed"],
|
| 2200 |
metrics["auto_heal_rate"],
|
|
|
|
| 2207 |
error_msg = f"❌ Error processing event: {str(e)}"
|
| 2208 |
logger.error(error_msg, exc_info=True)
|
| 2209 |
metrics = business_metrics.get_metrics()
|
| 2210 |
+
return (
|
| 2211 |
+
error_msg, {}, {}, gr.update(value=[]),
|
| 2212 |
metrics["total_incidents"],
|
| 2213 |
metrics["incidents_auto_healed"],
|
| 2214 |
metrics["auto_heal_rate"],
|
|
|
|
| 2236 |
)
|
| 2237 |
|
| 2238 |
return demo
|
| 2239 |
+
|
| 2240 |
+
# Create demo at module level for Hugging Face Spaces
|
| 2241 |
+
demo = create_enhanced_ui()
|
| 2242 |
+
|
| 2243 |
+
# === Main Entry Point ===
|
| 2244 |
if __name__ == "__main__":
|
| 2245 |
logger.info("=" * 80)
|
| 2246 |
logger.info("Starting Enterprise Agentic Reliability Framework (DEMO READY VERSION)")
|
|
|
|
| 2256 |
logger.info("=" * 80)
|
| 2257 |
|
| 2258 |
try:
|
|
|
|
|
|
|
| 2259 |
logger.info("Launching Gradio UI on 0.0.0.0:7860...")
|
| 2260 |
demo.launch(
|
| 2261 |
server_name="0.0.0.0",
|