Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- requirements.txt +63 -0
- st_live.py +154 -0
requirements.txt
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
altair==5.3.0
|
| 2 |
+
annotated-types==0.7.0
|
| 3 |
+
anyio==4.4.0
|
| 4 |
+
attrs==23.2.0
|
| 5 |
+
blinker==1.8.2
|
| 6 |
+
cachetools==5.3.3
|
| 7 |
+
certifi==2024.7.4
|
| 8 |
+
charset-normalizer==3.3.2
|
| 9 |
+
click==8.1.7
|
| 10 |
+
colorama==0.4.6
|
| 11 |
+
deprecation==2.1.0
|
| 12 |
+
Flask==3.0.3
|
| 13 |
+
gitdb==4.0.11
|
| 14 |
+
GitPython==3.1.43
|
| 15 |
+
gotrue==2.5.4
|
| 16 |
+
h11==0.14.0
|
| 17 |
+
httpcore==1.0.5
|
| 18 |
+
httpx==0.27.0
|
| 19 |
+
idna==3.7
|
| 20 |
+
itsdangerous==2.2.0
|
| 21 |
+
Jinja2==3.1.4
|
| 22 |
+
jsonschema==4.22.0
|
| 23 |
+
jsonschema-specifications==2023.12.1
|
| 24 |
+
markdown-it-py==3.0.0
|
| 25 |
+
MarkupSafe==2.1.5
|
| 26 |
+
mdurl==0.1.2
|
| 27 |
+
numpy==2.0.0
|
| 28 |
+
packaging==24.1
|
| 29 |
+
pandas==2.2.2
|
| 30 |
+
pillow==10.4.0
|
| 31 |
+
postgrest==0.16.8
|
| 32 |
+
protobuf==5.27.2
|
| 33 |
+
pyarrow==16.1.0
|
| 34 |
+
pydantic==2.8.2
|
| 35 |
+
pydantic_core==2.20.1
|
| 36 |
+
pydeck==0.9.1
|
| 37 |
+
Pygments==2.18.0
|
| 38 |
+
pyserial==3.5
|
| 39 |
+
python-dateutil==2.9.0.post0
|
| 40 |
+
pytz==2024.1
|
| 41 |
+
realtime==1.0.6
|
| 42 |
+
referencing==0.35.1
|
| 43 |
+
requests==2.32.3
|
| 44 |
+
rich==13.7.1
|
| 45 |
+
rpds-py==0.18.1
|
| 46 |
+
six==1.16.0
|
| 47 |
+
smmap==5.0.1
|
| 48 |
+
sniffio==1.3.1
|
| 49 |
+
storage3==0.7.6
|
| 50 |
+
streamlit==1.36.0
|
| 51 |
+
StrEnum==0.4.15
|
| 52 |
+
supabase==2.5.1
|
| 53 |
+
supafunc==0.4.6
|
| 54 |
+
tenacity==8.5.0
|
| 55 |
+
toml==0.10.2
|
| 56 |
+
toolz==0.12.1
|
| 57 |
+
tornado==6.4.1
|
| 58 |
+
typing_extensions==4.12.2
|
| 59 |
+
tzdata==2024.1
|
| 60 |
+
urllib3==2.2.2
|
| 61 |
+
watchdog==4.0.1
|
| 62 |
+
websockets==12.0
|
| 63 |
+
Werkzeug==3.0.3
|
st_live.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
import time
|
| 5 |
+
from supabase import create_client, Client
|
| 6 |
+
|
| 7 |
+
#"755_ #0_ON_36.00_21.00_Dry_8"
|
| 8 |
+
# Initialize the Supabase client
|
| 9 |
+
url: str = "https://jqwumpunrezhqtdruqbs.supabase.co" # Your Supabase URL
|
| 10 |
+
key: str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Impxd3VtcHVucmV6aHF0ZHJ1cWJzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTM5NTY5MTEsImV4cCI6MjAyOTUzMjkxMX0.0U4LdChmGtXxWnCODTWzQ8JgAgffkRcPhJ78x9s9rao" # Your Supabase API key
|
| 11 |
+
supabase: Client = create_client(url, key)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Function to simulate real-time data update
|
| 15 |
+
# Function to simulate real-time data update
|
| 16 |
+
def get_live_data():
|
| 17 |
+
response1 = supabase\
|
| 18 |
+
.from_("sensors")\
|
| 19 |
+
.select("t")\
|
| 20 |
+
.order("created_at", desc=True)\
|
| 21 |
+
.limit(1)\
|
| 22 |
+
.execute()
|
| 23 |
+
# Extract the data from the response
|
| 24 |
+
ky037 = int(response1.data[0]['t']) # Access the first item and the column 't'
|
| 25 |
+
|
| 26 |
+
response2 = supabase\
|
| 27 |
+
.from_("sensors")\
|
| 28 |
+
.select("sound")\
|
| 29 |
+
.order("created_at", desc=True)\
|
| 30 |
+
.limit(1)\
|
| 31 |
+
.execute()
|
| 32 |
+
# Extract the data from the response
|
| 33 |
+
speaker = int(response2.data[0]['sound']) # Access the first item and the column 'sound'
|
| 34 |
+
if speaker == 1:
|
| 35 |
+
speaker = "ON"
|
| 36 |
+
else:
|
| 37 |
+
speaker = "OFF"
|
| 38 |
+
|
| 39 |
+
response3 = supabase\
|
| 40 |
+
.from_("sensors")\
|
| 41 |
+
.select("hum")\
|
| 42 |
+
.order("created_at", desc=True)\
|
| 43 |
+
.limit(1)\
|
| 44 |
+
.execute()
|
| 45 |
+
# Extract the data from the response
|
| 46 |
+
hum = float(response3.data[0]['hum']) # Access the first item and the column 'hum'
|
| 47 |
+
|
| 48 |
+
response4 = supabase\
|
| 49 |
+
.from_("sensors")\
|
| 50 |
+
.select("temp")\
|
| 51 |
+
.order("created_at", desc=True)\
|
| 52 |
+
.limit(1)\
|
| 53 |
+
.execute()
|
| 54 |
+
# Extract the data from the response
|
| 55 |
+
temp = float(response4.data[0]['temp']) # Access the first item and the column 'temp'
|
| 56 |
+
|
| 57 |
+
response5 = supabase\
|
| 58 |
+
.from_("sensors")\
|
| 59 |
+
.select("rain")\
|
| 60 |
+
.order("created_at", desc=True)\
|
| 61 |
+
.limit(1)\
|
| 62 |
+
.execute()
|
| 63 |
+
# Extract the data from the response
|
| 64 |
+
wet = int(response5.data[0]['rain']) # Access the first item and the column 'rain'
|
| 65 |
+
if wet == 1:
|
| 66 |
+
wet = "Dry"
|
| 67 |
+
else:
|
| 68 |
+
wet = "Wet"
|
| 69 |
+
|
| 70 |
+
response6 = supabase\
|
| 71 |
+
.from_("sensors")\
|
| 72 |
+
.select("x")\
|
| 73 |
+
.order("created_at", desc=True)\
|
| 74 |
+
.limit(1)\
|
| 75 |
+
.execute()
|
| 76 |
+
# Extract the data from the response
|
| 77 |
+
light = int(response6.data[0]['x']) # Access the first item and the column 'x'
|
| 78 |
+
|
| 79 |
+
return ky037, speaker, light, wet, hum, temp
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def main():
|
| 84 |
+
st.markdown("<h1 style='text-align: center;'> گهوارهی هوشمند </h1>", unsafe_allow_html=True)
|
| 85 |
+
st.markdown("<p style='text-align: center; font-size: 30px;'>:وضعیت</p>", unsafe_allow_html=True)
|
| 86 |
+
|
| 87 |
+
# Create placeholders for each message and the table
|
| 88 |
+
message_placeholder = st.empty()
|
| 89 |
+
light_message_placeholder = st.empty()
|
| 90 |
+
wet_message_placeholder = st.empty()
|
| 91 |
+
temp_message_placeholder = st.empty()
|
| 92 |
+
table_placeholder = st.empty()
|
| 93 |
+
|
| 94 |
+
# Start the live update loop
|
| 95 |
+
while True:
|
| 96 |
+
result = get_live_data()
|
| 97 |
+
if result is not None:
|
| 98 |
+
ky037, speaker, light, wet, hum, temp = result
|
| 99 |
+
|
| 100 |
+
# Update messages
|
| 101 |
+
if light >= 980:
|
| 102 |
+
light_status = "تاریک"
|
| 103 |
+
else:
|
| 104 |
+
light_status = 'روشن'
|
| 105 |
+
|
| 106 |
+
if ky037 >= 3 and light_status == "روشن":
|
| 107 |
+
light_message_placeholder.markdown("<p style='text-align: center; font-size: 15px;'>.پیشنهاد میشود نور محیط را کم کنید</p>", unsafe_allow_html=True)
|
| 108 |
+
else:
|
| 109 |
+
light_message_placeholder.empty()
|
| 110 |
+
|
| 111 |
+
if ky037 >= 3:
|
| 112 |
+
ky037_status = ".کودک گریه میکند"
|
| 113 |
+
else:
|
| 114 |
+
ky037_status = ".کودک گریه نمیکند"
|
| 115 |
+
|
| 116 |
+
message_placeholder.markdown(f"<p style='text-align: center; font-size: 15px;'>{ky037_status}</p>", unsafe_allow_html=True)
|
| 117 |
+
|
| 118 |
+
if wet == "Wet":
|
| 119 |
+
wet_status = "Wet"
|
| 120 |
+
wet_message_placeholder.markdown("<p style='text-align: center; font-size: 15px;'>.زیرانداز کودک را عوض کنید</p>", unsafe_allow_html=True)
|
| 121 |
+
else:
|
| 122 |
+
wet_status = "Dry"
|
| 123 |
+
wet_message_placeholder.empty()
|
| 124 |
+
|
| 125 |
+
if temp < 20:
|
| 126 |
+
temp_message_placeholder.markdown("<p style='text-align: center; font-size: 15px;'>.اتاق سرد است</p>", unsafe_allow_html=True)
|
| 127 |
+
elif temp > 24:
|
| 128 |
+
temp_message_placeholder.markdown("<p style='text-align: center; font-size: 15px;'>.اتاق گرم است</p>", unsafe_allow_html=True)
|
| 129 |
+
else:
|
| 130 |
+
temp_message_placeholder.empty()
|
| 131 |
+
|
| 132 |
+
data = {
|
| 133 |
+
'وضعیت': [ky037_status, light_status, wet_status, hum, temp],
|
| 134 |
+
'سنسور': ['صدا', 'نور','تخت کودک','(%)رطوبت محیط','(^C)دمای محیط']
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
df = pd.DataFrame(data)
|
| 138 |
+
|
| 139 |
+
st.markdown("""
|
| 140 |
+
<style>
|
| 141 |
+
.stTable tr {
|
| 142 |
+
height: 50px; /* Adjust this value to change the row height */
|
| 143 |
+
}
|
| 144 |
+
</style>
|
| 145 |
+
""", unsafe_allow_html=True)
|
| 146 |
+
|
| 147 |
+
# Update the table in the placeholder
|
| 148 |
+
table_placeholder.table(df)
|
| 149 |
+
time. sleep(5)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
if __name__ == "__main__":
|
| 154 |
+
main()
|