tstone87 commited on
Commit
cac62cc
·
verified ·
1 Parent(s): 1209a44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -5
app.py CHANGED
@@ -11,20 +11,34 @@ import streamlink
11
  # Page Config
12
  st.set_page_config(page_title="AI Fire Watch", page_icon="🌍", layout="wide")
13
 
14
- # Lighter Background CSS
15
  st.markdown(
16
  """
17
  <style>
18
  .stApp {
19
  background-color: #f5f5f5;
20
- color: #333333;
 
 
 
21
  }
22
  .stTabs > div > button {
23
  background-color: #e0e0e0;
24
- color: #333333;
 
25
  }
26
  .stTabs > div > button:hover {
27
  background-color: #d0d0d0;
 
 
 
 
 
 
 
 
 
 
28
  }
29
  </style>
30
  """,
@@ -39,6 +53,12 @@ except Exception as ex:
39
  st.error(f"Model loading failed: {ex}")
40
  st.stop()
41
 
 
 
 
 
 
 
42
  # Header
43
  st.title("AI Fire Watch")
44
  st.markdown("Monitor fire and smoke in real-time with AI precision.")
@@ -87,15 +107,25 @@ with tabs[1]:
87
  webcam_url = st.text_input("Webcam URL", "http://<your_webcam_ip>/current.jpg", label_visibility="collapsed")
88
  confidence = st.slider("Detection Threshold", 0.25, 1.0, 0.4, key="webcam_conf")
89
  start = st.button("Begin Monitoring", key="webcam_start")
90
- with col2:
 
 
91
  if start:
 
 
 
 
 
 
 
 
92
  image_placeholder = st.empty()
93
  timer_placeholder = st.empty()
94
  refresh_interval = 30 # Refresh every 30 seconds
95
  while True:
96
  start_time = time.time()
97
  try:
98
- response = requests.get(webcam_url, timeout=5)
99
  if response.status_code != 200:
100
  st.error(f"Fetch failed: HTTP {response.status_code}")
101
  break
@@ -118,6 +148,7 @@ with tabs[1]:
118
  st.experimental_rerun()
119
  except Exception as e:
120
  st.error(f"Error: {e}")
 
121
  break
122
 
123
  # Tab 3: YouTube
 
11
  # Page Config
12
  st.set_page_config(page_title="AI Fire Watch", page_icon="🌍", layout="wide")
13
 
14
+ # Lighter Background CSS with Darker Text
15
  st.markdown(
16
  """
17
  <style>
18
  .stApp {
19
  background-color: #f5f5f5;
20
+ color: #1a1a1a; /* Dark text for general content */
21
+ }
22
+ h1 {
23
+ color: #1a1a1a; /* Darker title text */
24
  }
25
  .stTabs > div > button {
26
  background-color: #e0e0e0;
27
+ color: #1a1a1a; /* Darker tab text */
28
+ font-weight: bold;
29
  }
30
  .stTabs > div > button:hover {
31
  background-color: #d0d0d0;
32
+ color: #1a1a1a;
33
+ }
34
+ .stButton > button {
35
+ background-color: #e0e0e0;
36
+ color: #1a1a1a; /* Darker button text */
37
+ font-weight: bold;
38
+ }
39
+ .stButton > button:hover {
40
+ background-color: #d0d0d0;
41
+ color: #1a1a1a;
42
  }
43
  </style>
44
  """,
 
53
  st.error(f"Model loading failed: {ex}")
54
  st.stop()
55
 
56
+ # Initialize Session State
57
+ if 'monitoring' not in st.session_state:
58
+ st.session_state.monitoring = False
59
+ if 'current_webcam_url' not in st.session_state:
60
+ st.session_state.current_webcam_url = None
61
+
62
  # Header
63
  st.title("AI Fire Watch")
64
  st.markdown("Monitor fire and smoke in real-time with AI precision.")
 
107
  webcam_url = st.text_input("Webcam URL", "http://<your_webcam_ip>/current.jpg", label_visibility="collapsed")
108
  confidence = st.slider("Detection Threshold", 0.25, 1.0, 0.4, key="webcam_conf")
109
  start = st.button("Begin Monitoring", key="webcam_start")
110
+ stop = st.button("Stop Monitoring", key="webcam_stop")
111
+
112
+ # Handle monitoring state
113
  if start:
114
+ st.session_state.monitoring = True
115
+ st.session_state.current_webcam_url = webcam_url
116
+ if stop or (st.session_state.monitoring and webcam_url != st.session_state.current_webcam_url):
117
+ st.session_state.monitoring = False
118
+ st.session_state.current_webcam_url = None
119
+
120
+ with col2:
121
+ if st.session_state.monitoring and st.session_state.current_webcam_url:
122
  image_placeholder = st.empty()
123
  timer_placeholder = st.empty()
124
  refresh_interval = 30 # Refresh every 30 seconds
125
  while True:
126
  start_time = time.time()
127
  try:
128
+ response = requests.get(st.session_state.current_webcam_url, timeout=5)
129
  if response.status_code != 200:
130
  st.error(f"Fetch failed: HTTP {response.status_code}")
131
  break
 
148
  st.experimental_rerun()
149
  except Exception as e:
150
  st.error(f"Error: {e}")
151
+ st.session_state.monitoring = False
152
  break
153
 
154
  # Tab 3: YouTube