-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (44 loc) · 1.78 KB
/
Copy pathapp.py
File metadata and controls
57 lines (44 loc) · 1.78 KB
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
import gradio as gr
import plotly.express as px
from src.anomaly_engine import anomaly_engine
def run_analysis():
df = anomaly_engine.generate_sample_data()
df = anomaly_engine.detect_anomalies(df)
# Create plot
fig = px.line(df, x="timestamp", y=["temperature", "pressure", "vibration"], title="Sensor Telemetry")
# Highlight anomalies
anomalies = df[df["is_anomaly"]]
for idx, row in anomalies.iterrows():
fig.add_annotation(x=row["timestamp"], y=row["temperature"], text="Anomaly", showarrow=True, arrowhead=1)
# Analyze the most significant anomaly
analysis = "No significant anomalies detected."
if not anomalies.empty:
analysis = anomaly_engine.analyze_root_cause(anomalies.tail(1))
return fig, analysis
# ============================================
# GRADIO UI
# ============================================
with gr.Blocks(title="IoT Anomaly Agent", theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# IoT Anomaly Agent
### Turbine Anomaly Detection Agent
Using **Isolation Forest** for detection and **Mistral-7B** for Root Cause Analysis (RCA).
""")
with gr.Row():
with gr.Column(scale=2):
plot_output = gr.Plot(label="Telemetry Stream")
with gr.Column(scale=1):
analysis_output = gr.Markdown(label="Root Cause Analysis")
run_btn = gr.Button("Analyze Stream", variant="primary")
run_btn.click(
fn=run_analysis,
inputs=[],
outputs=[plot_output, analysis_output]
)
gr.Markdown("""
---
**Tech Stack:** Isolation Forest • Mistral-7B • Plotly • Gradio
**Author:** [David Fernandez](https://davidfernandez.dev) | AI Engineer
""")
if __name__ == "__main__":
demo.launch()