Spaces:
Running
Running
File size: 4,447 Bytes
f3ce5ec | 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 | import gradio as gr
import pandas as pd
import plotly.graph_objects as go
def safety_agent(fire_alarm, exits_clear, hazards):
score = 100
if not fire_alarm:
score -= 35
if not exits_clear:
score -= 35
score -= hazards * 10
return max(score, 0)
def security_agent(cctv, access_control, incidents):
score = 100
if not cctv:
score -= 30
if not access_control:
score -= 30
score -= incidents * 15
return max(score, 0)
def reliability_agent(elevator_ok, hvac_ok, power_backup, maintenance_issues):
score = 100
if not elevator_ok:
score -= 25
if not hvac_ok:
score -= 25
if not power_backup:
score -= 25
score -= maintenance_issues * 10
return max(score, 0)
def status_label(score):
if score >= 80:
return "GOOD"
elif score >= 60:
return "WARNING"
else:
return "CRITICAL"
def evaluate_building(
fire_alarm, exits_clear, hazards,
cctv, access_control, incidents,
elevator_ok, hvac_ok, power_backup, maintenance_issues
):
safety = safety_agent(fire_alarm, exits_clear, hazards)
security = security_agent(cctv, access_control, incidents)
reliability = reliability_agent(elevator_ok, hvac_ok, power_backup, maintenance_issues)
overall = round((safety + security + reliability) / 3, 2)
df = pd.DataFrame({
"Agent": ["Safety", "Security", "Reliability", "Overall"],
"Score": [safety, security, reliability, overall],
"Status": [
status_label(safety),
status_label(security),
status_label(reliability),
status_label(overall)
]
})
fig = go.Figure()
fig.add_trace(go.Bar(
x=df["Agent"],
y=df["Score"],
text=df["Status"],
textposition="auto"
))
fig.update_layout(
title="Building Safety, Security, and Reliability Status",
yaxis=dict(range=[0, 100]),
xaxis_title="Evaluation Agent",
yaxis_title="Score"
)
report = f"""
# Building Evaluation Report
## Overall Status: {status_label(overall)}
Overall Score: {overall}/100
## Agent Results
- Safety Score: {safety}/100 — {status_label(safety)}
- Security Score: {security}/100 — {status_label(security)}
- Reliability Score: {reliability}/100 — {status_label(reliability)}
## Recommendation
"""
if overall >= 80:
report += "The building condition is acceptable. Continue regular monitoring."
elif overall >= 60:
report += "The building needs attention. Some risks are present and should be addressed soon."
else:
report += "The building is in critical condition. Immediate action is required."
return df, fig, report
with gr.Blocks(title="Building Multi-Agent Risk Evaluation") as demo:
gr.Markdown("# Multi-Agent Building Safety, Security, and Reliability Evaluator")
with gr.Row():
with gr.Column():
gr.Markdown("## Safety Agent")
fire_alarm = gr.Checkbox(label="Fire alarm working", value=True)
exits_clear = gr.Checkbox(label="Emergency exits clear", value=True)
hazards = gr.Slider(0, 5, step=1, label="Number of visible hazards")
with gr.Column():
gr.Markdown("## Security Agent")
cctv = gr.Checkbox(label="CCTV working", value=True)
access_control = gr.Checkbox(label="Access control active", value=True)
incidents = gr.Slider(0, 5, step=1, label="Recent security incidents")
with gr.Column():
gr.Markdown("## Reliability Agent")
elevator_ok = gr.Checkbox(label="Elevator working", value=True)
hvac_ok = gr.Checkbox(label="HVAC working", value=True)
power_backup = gr.Checkbox(label="Backup power available", value=True)
maintenance_issues = gr.Slider(0, 5, step=1, label="Maintenance issues")
btn = gr.Button("Evaluate Building")
output_table = gr.Dataframe(label="Agent Scores")
output_chart = gr.Plot(label="Status Chart")
output_report = gr.Markdown(label="Report")
btn.click(
evaluate_building,
inputs=[
fire_alarm, exits_clear, hazards,
cctv, access_control, incidents,
elevator_ok, hvac_ok, power_backup, maintenance_issues
],
outputs=[output_table, output_chart, output_report]
)
demo.launch() |