fouadmahmoud283-ai commited on
Commit
90cbac0
·
1 Parent(s): 36a5118

Add working demo images from Unsplash and improve file upload configuration

Browse files
Files changed (3) hide show
  1. .streamlit/config.toml +3 -0
  2. requirements.txt +2 -1
  3. src/streamlit_app.py +62 -17
.streamlit/config.toml CHANGED
@@ -2,9 +2,12 @@
2
  maxUploadSize = 200
3
  enableCORS = false
4
  enableXsrfProtection = false
 
 
5
 
6
  [browser]
7
  gatherUsageStats = false
 
8
 
9
  [theme]
10
  primaryColor = "#2E86AB"
 
2
  maxUploadSize = 200
3
  enableCORS = false
4
  enableXsrfProtection = false
5
+ headless = true
6
+ port = 8501
7
 
8
  [browser]
9
  gatherUsageStats = false
10
+ serverAddress = "0.0.0.0"
11
 
12
  [theme]
13
  primaryColor = "#2E86AB"
requirements.txt CHANGED
@@ -11,4 +11,5 @@ matplotlib
11
  seaborn
12
  ultralytics
13
  av
14
- aiortc
 
 
11
  seaborn
12
  ultralytics
13
  av
14
+ aiortc
15
+ requests
src/streamlit_app.py CHANGED
@@ -13,6 +13,7 @@ import tempfile
13
  import os
14
  import logging
15
  import warnings
 
16
 
17
  # Suppress WebRTC/asyncio warnings and errors
18
  logging.getLogger('aioice').setLevel(logging.CRITICAL)
@@ -104,6 +105,29 @@ if 'model' not in st.session_state:
104
  st.session_state.model = None
105
  if 'detection_history' not in st.session_state:
106
  st.session_state.detection_history = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  # Wheelchair-relevant classes from COCO
109
  WHEELCHAIR_CLASSES = {
@@ -347,23 +371,38 @@ def main():
347
  with col1:
348
  st.markdown("### 📷 Upload Image for Detection")
349
 
350
- # Option to use demo or upload
351
- demo_option = st.radio(
352
- "Choose input method:",
353
- ["Upload Image", "Use Demo (Coming Soon)"],
354
- horizontal=True
355
  )
356
 
357
- uploaded_file = None
358
- if demo_option == "Upload Image":
359
- uploaded_file = st.file_uploader(
360
- "Choose an image...",
361
- type=['jpg', 'jpeg', 'png', 'bmp'],
362
- help="Upload an image to test wheelchair navigation detection. Max size: 200MB",
363
- key="image_uploader"
364
- )
365
- else:
366
- st.info("📌 Demo images feature coming soon! Please use 'Upload Image' option for now.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
 
368
  with col2:
369
  st.markdown("### 🛡️ Safety Status")
@@ -372,10 +411,16 @@ def main():
372
  st.markdown("### 🧭 Navigation Advice")
373
  advice_placeholder = st.empty()
374
 
375
- # Process uploaded image
 
376
  if uploaded_file is not None:
377
- # Load and display original image
378
  image = Image.open(uploaded_file)
 
 
 
 
 
379
 
380
  col1, col2 = st.columns(2)
381
 
 
13
  import os
14
  import logging
15
  import warnings
16
+ import requests
17
 
18
  # Suppress WebRTC/asyncio warnings and errors
19
  logging.getLogger('aioice').setLevel(logging.CRITICAL)
 
105
  st.session_state.model = None
106
  if 'detection_history' not in st.session_state:
107
  st.session_state.detection_history = []
108
+ if 'current_image' not in st.session_state:
109
+ st.session_state.current_image = None
110
+ if 'demo_selected' not in st.session_state:
111
+ st.session_state.demo_selected = False
112
+
113
+ # Demo images URLs (publicly accessible images)
114
+ DEMO_IMAGES = {
115
+ "Indoor Scene": "https://images.unsplash.com/photo-1555992336-fb0d29498b13?w=800&q=80", # Office/indoor
116
+ "Outdoor Scene": "https://images.unsplash.com/photo-1519501025264-65ba15a82390?w=800&q=80", # Street scene
117
+ "Crowded Area": "https://images.unsplash.com/photo-1528543606781-2f6e6857f318?w=800&q=80" # Crowded place
118
+ }
119
+
120
+ def load_demo_image(demo_name):
121
+ """Load demo image from URL"""
122
+ try:
123
+ url = DEMO_IMAGES[demo_name]
124
+ response = requests.get(url, timeout=10)
125
+ response.raise_for_status()
126
+ image = Image.open(io.BytesIO(response.content))
127
+ return image
128
+ except Exception as e:
129
+ st.error(f"Error loading demo image: {e}")
130
+ return None
131
 
132
  # Wheelchair-relevant classes from COCO
133
  WHEELCHAIR_CLASSES = {
 
371
  with col1:
372
  st.markdown("### 📷 Upload Image for Detection")
373
 
374
+ uploaded_file = st.file_uploader(
375
+ "Choose an image...",
376
+ type=['jpg', 'jpeg', 'png', 'bmp'],
377
+ help="Upload an image to test wheelchair navigation detection",
378
+ key="image_uploader"
379
  )
380
 
381
+ # Demo images buttons
382
+ st.markdown("### 🎬 Or Try Demo Images")
383
+ demo_col1, demo_col2, demo_col3 = st.columns(3)
384
+
385
+ demo_image = None
386
+ with demo_col1:
387
+ if st.button("🏪 Indoor Scene", use_container_width=True):
388
+ st.session_state.demo_selected = True
389
+ demo_image = load_demo_image("Indoor Scene")
390
+ if demo_image:
391
+ st.session_state.current_image = demo_image
392
+
393
+ with demo_col2:
394
+ if st.button("🏙️ Outdoor Scene", use_container_width=True):
395
+ st.session_state.demo_selected = True
396
+ demo_image = load_demo_image("Outdoor Scene")
397
+ if demo_image:
398
+ st.session_state.current_image = demo_image
399
+
400
+ with demo_col3:
401
+ if st.button("🚶 Crowded Area", use_container_width=True):
402
+ st.session_state.demo_selected = True
403
+ demo_image = load_demo_image("Crowded Area")
404
+ if demo_image:
405
+ st.session_state.current_image = demo_image
406
 
407
  with col2:
408
  st.markdown("### 🛡️ Safety Status")
 
411
  st.markdown("### 🧭 Navigation Advice")
412
  advice_placeholder = st.empty()
413
 
414
+ # Process uploaded or demo image
415
+ image = None
416
  if uploaded_file is not None:
417
+ st.session_state.demo_selected = False
418
  image = Image.open(uploaded_file)
419
+ st.session_state.current_image = image
420
+ elif st.session_state.demo_selected and st.session_state.current_image is not None:
421
+ image = st.session_state.current_image
422
+
423
+ if image is not None:
424
 
425
  col1, col2 = st.columns(2)
426