Skip to content

Commit

Permalink
Merge pull request #194 from Shibika-Roy/add-streamlit-monitoring
Browse files Browse the repository at this point in the history
Add Streamlit app for real-time IoT heart rate and stress monitoring
  • Loading branch information
Amna-Hassan04 authored Nov 10, 2024
2 parents d514c05 + e537a70 commit 2dedb49
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
58 changes: 58 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,64 @@ def global_error_handler(exc_type, exc_value, exc_traceback):
</style>
"""

import streamlit as st
import random
import time
# Adding tabs for different sections of the app
tabs = st.tabs(["Home", "Guided Meditation", "Breathing Exercises", "Monitoring (Beta)"])
# Code for the Monitoring (Beta) tab
import streamlit as st
import random
import time

# Add navigation options in sidebar
selected_tab = st.sidebar.selectbox("Choose a tab", ["Home", "Monitoring (Beta)", "Other Tabs"])

if selected_tab == "Monitoring (Beta)":
st.title("Monitoring (Beta)")
st.subheader("Connect Your Heart Rate and Stress Monitoring Device")

# Connection instructions
st.markdown("""
To connect your device, please follow these steps:
1. **Enable Bluetooth** on your heart rate monitoring device and the device running this app.
2. **Select Your Device** from the dropdown below and click **Connect**.
3. Once connected, your heart rate and stress levels will appear in real-time.
""")

# Simulated dropdown to select a device (for demonstration purposes)
device_name = st.selectbox("Select Monitoring Device", ["Device 1", "Device 2", "Device 3"])

# Simulate a connect button
if st.button("Connect"):
st.success(f"Connected to {device_name}!")

# Display placeholders for real-time data
heart_rate_display = st.empty()
stress_level_display = st.empty()
status_display = st.empty()

def simulate_data():
"""Simulate heart rate and stress level data"""
heart_rate = random.randint(60, 100)
stress_level = random.randint(1, 10)
return heart_rate, stress_level

# Real-time update loop
status_display.write("Monitoring real-time data...")

for _ in range(100): # Use a finite range instead of while True for demonstration
# Simulate or fetch data
heart_rate, stress_level = simulate_data()

# Display the data in real-time
heart_rate_display.metric("Heart Rate", f"{heart_rate} BPM")
stress_level_display.metric("Stress Level", f"{stress_level}/10")

# Refresh data every second
time.sleep(1)
#Changes made by --Charvi Arora
#Added security
# Load environment variables from .env file
load_dotenv()
Expand Down
57 changes: 57 additions & 0 deletions streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import streamlit as st

# Main App Title
st.title("SereniFi Guide")

# Tabs for Navigation
tab1, tab2, tab3 = st.tabs(["Calm Space", "Monitoring (Beta)", "About and Feedback"])

# Calm Space Tab Content
with tab1:
st.header("Calm Space")
# Existing content for Calm Space
st.write("Welcome to your Calm Space.")

# Monitoring (Beta) Tab Content
with tab2:
st.header("Monitoring (Beta)")
st.write("Connect your heart rate and stress monitoring device below.")

# Instructions for connecting a monitoring device
st.markdown("""
**Steps to Connect:**
1. Enable Bluetooth on your device.
2. Select your wearable device from the available options below.
- Example Device 1
- Example Device 2
3. Once connected, real-time monitoring data will display here.
""")

# Example placeholders for real-time data
st.metric(label="Heart Rate", value="72 bpm")
st.metric(label="Stress Level", value="Low")

# About and Feedback Tab Content
with tab3:
st.header("About and Feedback")
# Content for About and Feedback
st.write("This section provides information and allows feedback.")

# Display placeholders for real-time data
heart_rate_display = st.empty()
stress_level_display = st.empty()
status_display = st.empty()

def simulate_data():
"""Simulate heart rate and stress level data"""
heart_rate = random.randint(60, 100)
stress_level = random.randint(1, 10)
return heart_rate, stress_level

# Real-time update loop
status_display.write("Monitoring real-time data...")
for _ in range(100): # Finite loop for demonstration
heart_rate, stress_level = simulate_data()
heart_rate_display.metric("Heart Rate", f"{heart_rate} BPM")
stress_level_display.metric("Stress Level", f"{stress_level}/10")
time.sleep(1)

0 comments on commit 2dedb49

Please sign in to comment.