Neylton commited on
Commit
abb580d
Β·
verified Β·
1 Parent(s): 012ffb4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -30
app.py CHANGED
@@ -193,18 +193,25 @@ st.markdown("""
193
  object-fit: contain;
194
  }
195
 
196
- /* Camera input styling */
197
- .stCamera > div {
198
  border-radius: 15px;
199
- overflow: hidden;
200
- box-shadow: 0 4px 15px rgba(0,0,0,0.1);
201
  margin: 10px 0;
202
  }
203
 
204
- /* File uploader styling */
205
- .stFileUploader > div {
206
  border-radius: 15px;
207
- margin: 10px 0;
 
 
 
 
 
 
 
 
 
208
  }
209
 
210
  /* Mobile responsive adjustments */
@@ -482,41 +489,29 @@ def main():
482
  </div>
483
  """, unsafe_allow_html=True)
484
 
485
- # Camera input for mobile devices
486
- st.markdown("**πŸ“± Take a Live Photo**")
487
- camera_photo = st.camera_input(
488
- "πŸ“Έ Take a picture",
489
- help="Use your device camera to take a photo for fire detection"
490
- )
491
 
492
- # File uploader for existing images
493
- st.markdown("**πŸ“ Or Upload from Device**")
494
  uploaded_file = st.file_uploader(
495
- "Choose an image...",
496
  type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
497
- help="Upload an existing image from your device for fire detection"
498
  )
499
 
500
- # Determine which input was used
501
  image = None
502
- image_source = None
503
 
504
- if camera_photo is not None:
505
- image = Image.open(camera_photo)
506
- image_source = "camera"
507
- elif uploaded_file is not None:
508
  image = Image.open(uploaded_file)
509
  image_source = "uploaded"
510
 
511
  # Process the image (whether uploaded or from camera)
512
  if image is not None:
513
  # Display the image with appropriate caption
514
- caption_map = {
515
- "camera": "πŸ“· Camera Photo",
516
- "uploaded": "πŸ“ Uploaded Image"
517
- }
518
- caption = caption_map.get(image_source, "Image")
519
- st.image(image, caption=caption, use_column_width=True)
520
 
521
  # Get prediction
522
  transform = get_inference_transform()
@@ -532,7 +527,6 @@ def main():
532
  with st.expander("πŸ”¬ Technical Details"):
533
  st.markdown(f"""
534
  **Prediction Details:**
535
- - Input Source: {image_source.title()}
536
  - Predicted Class: {predicted_label}
537
  - Confidence Score: {confidence_score:.4f}
538
  - Fire Probability: {all_probs[0]:.4f}
 
193
  object-fit: contain;
194
  }
195
 
196
+ /* File uploader styling - enhanced for mobile */
197
+ .stFileUploader > div {
198
  border-radius: 15px;
 
 
199
  margin: 10px 0;
200
  }
201
 
202
+ .stFileUploader > div > div {
203
+ border: 2px dashed #74b9ff;
204
  border-radius: 15px;
205
+ padding: 20px;
206
+ background: rgba(116, 185, 255, 0.05);
207
+ transition: all 0.3s ease;
208
+ }
209
+
210
+ .stFileUploader > div > div:hover {
211
+ border-color: #0984e3;
212
+ background: rgba(116, 185, 255, 0.1);
213
+ transform: translateY(-2px);
214
+ box-shadow: 0 4px 15px rgba(116, 185, 255, 0.2);
215
  }
216
 
217
  /* Mobile responsive adjustments */
 
489
  </div>
490
  """, unsafe_allow_html=True)
491
 
492
+ # Mobile-friendly file uploader that opens native camera
493
+ st.markdown("**πŸ“± Take Photo or Upload Image**")
494
+ st.markdown("πŸ“Έ **On Mobile**: Tap below β†’ Choose 'Take Photo' to open camera")
495
+ st.markdown("πŸ’» **On Desktop**: Click below to select image files")
 
 
496
 
 
 
497
  uploaded_file = st.file_uploader(
498
+ "Choose an image or take a photo...",
499
  type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
500
+ help="πŸ“± Mobile: Tap to open camera or gallery | πŸ’» Desktop: Click to browse files"
501
  )
502
 
503
+ # Process the uploaded image
504
  image = None
505
+ image_source = "uploaded"
506
 
507
+ if uploaded_file is not None:
 
 
 
508
  image = Image.open(uploaded_file)
509
  image_source = "uploaded"
510
 
511
  # Process the image (whether uploaded or from camera)
512
  if image is not None:
513
  # Display the image with appropriate caption
514
+ st.image(image, caption="πŸ“Έ Your Image", use_column_width=True)
 
 
 
 
 
515
 
516
  # Get prediction
517
  transform = get_inference_transform()
 
527
  with st.expander("πŸ”¬ Technical Details"):
528
  st.markdown(f"""
529
  **Prediction Details:**
 
530
  - Predicted Class: {predicted_label}
531
  - Confidence Score: {confidence_score:.4f}
532
  - Fire Probability: {all_probs[0]:.4f}