-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
63 lines (51 loc) · 2.65 KB
/
Copy pathapp.py
File metadata and controls
63 lines (51 loc) · 2.65 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
58
59
60
61
62
63
import streamlit as st
import random
from utils import get_system_decision, get_ai_insight
# Setup the main page configuration
st.set_page_config(page_title="SmartSense AI", page_icon="🌡️", layout="centered")
st.title("🌡️ SmartSense AI")
st.subheader("Intelligent IoT Monitoring Assistant")
st.markdown("""
Welcome to **SmartSense AI**! This dashboard simulates an intelligent environmental monitoring and energy management system.
It uses rule-based logic (similar to an Arduino with an LM35 sensor) to make decisions based on temperature and occupancy,
and integrates Google's Gemini AI to explain its actions in plain English.
""")
# Sidebar for simulation controls
st.sidebar.header("⚙️ Sensor Inputs")
# Auto mode toggle for random values
auto_mode = st.sidebar.toggle("Auto Mode (Simulate Sensor Data)")
if auto_mode:
temperature = round(random.uniform(12.0, 38.0), 1)
occupancy = random.randint(0, 5)
st.sidebar.info("Auto Mode is ON. Sensor values are randomly updating.")
else:
temperature = st.sidebar.slider("Temperature (°C)", min_value=10.0, max_value=40.0, value=24.0, step=0.5)
occupancy = st.sidebar.number_input("Occupancy (Number of people)", min_value=0, max_value=20, value=1, step=1)
# Display current sensor readings
col1, col2 = st.columns(2)
with col1:
st.metric(label="Current Temperature", value=f"{temperature} °C")
with col2:
st.metric(label="Room Occupancy", value=f"{occupancy} Person(s)")
# Run our core decision logic
decision, basic_reason = get_system_decision(temperature, occupancy)
# Display System Status
st.header("⚡ System Status")
status_color = "green" if decision == "OFF" else "blue" if decision == "COOLING ON" else "orange" if decision == "HEATING ON" else "gray"
st.markdown(f"### Recommendation: :{status_color}[{decision}]")
st.write(f"**Logic Engine Output:** {basic_reason}")
# Fetch and display AI Insights
st.header("🤖 AI Insight (Powered by Gemini)")
with st.spinner("Generating AI explanation..."):
ai_insight = get_ai_insight(temperature, occupancy, decision, basic_reason)
st.info(ai_insight)
# Bonus Feature: Alerts based on extreme conditions
st.divider()
if temperature > 30 and occupancy > 0:
st.warning("🚨 Alert: High temperature detected! Cooling is highly recommended to maintain comfort.")
elif temperature < 15 and occupancy > 0:
st.warning("🚨 Alert: Low temperature detected! Heating is required.")
elif occupancy == 0 and decision != "OFF":
# Should not happen with our logic, but just in case
st.warning("🚨 Alert: System is running in an empty room. Wasting energy!")
st.caption("Built for Hackathon | Powered by Python, Streamlit & Google Gemini API")