Neylton commited on
Commit
870e83f
·
verified ·
1 Parent(s): 257b945

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -11
app.py CHANGED
@@ -192,6 +192,56 @@ st.markdown("""
192
  width: auto;
193
  object-fit: contain;
194
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  </style>
196
  """, unsafe_allow_html=True)
197
 
@@ -432,21 +482,44 @@ def main():
432
  # Upload section
433
  st.markdown("""
434
  <div class="upload-section">
435
- <h3>📸 Upload Data Center Image</h3>
436
- <p>Upload an image to detect fire or smoke in your data center</p>
437
  </div>
438
  """, unsafe_allow_html=True)
439
 
440
- uploaded_file = st.file_uploader(
441
- "Choose an image...",
442
- type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
443
- help="Upload an image from your data center for fire detection"
444
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
 
446
- if uploaded_file is not None:
447
- # Display uploaded image
448
- image = Image.open(uploaded_file)
449
- st.image(image, caption="Uploaded Image", use_column_width=True)
 
450
 
451
  # Get prediction
452
  transform = get_inference_transform()
@@ -462,6 +535,7 @@ def main():
462
  with st.expander("🔬 Technical Details"):
463
  st.markdown(f"""
464
  **Prediction Details:**
 
465
  - Predicted Class: {predicted_label}
466
  - Confidence Score: {confidence_score:.4f}
467
  - Fire Probability: {all_probs[0]:.4f}
 
192
  width: auto;
193
  object-fit: contain;
194
  }
195
+
196
+ /* Mobile-friendly camera and tabs */
197
+ .stTabs > div > div > div > div {
198
+ padding: 10px 15px;
199
+ font-weight: bold;
200
+ }
201
+
202
+ .stTabs > div > div > div > div[aria-selected="true"] {
203
+ background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
204
+ color: white;
205
+ border-radius: 10px;
206
+ }
207
+
208
+ /* Camera input styling */
209
+ .stCamera > div {
210
+ border-radius: 15px;
211
+ overflow: hidden;
212
+ box-shadow: 0 4px 15px rgba(0,0,0,0.1);
213
+ }
214
+
215
+ /* Mobile responsive adjustments */
216
+ @media (max-width: 768px) {
217
+ .main-header h1 {
218
+ font-size: 2rem;
219
+ }
220
+
221
+ .main-header p {
222
+ font-size: 1rem;
223
+ }
224
+
225
+ .upload-section {
226
+ height: 80px;
227
+ }
228
+
229
+ .upload-section h3 {
230
+ font-size: 1.1rem;
231
+ }
232
+
233
+ .result-fire h2, .result-no-fire h2 {
234
+ font-size: 1rem;
235
+ }
236
+
237
+ .result-fire, .result-no-fire {
238
+ height: 80px;
239
+ }
240
+
241
+ .stImage > img {
242
+ max-height: 300px;
243
+ }
244
+ }
245
  </style>
246
  """, unsafe_allow_html=True)
247
 
 
482
  # Upload section
483
  st.markdown("""
484
  <div class="upload-section">
485
+ <h3>📸 Fire Detection Input</h3>
486
+ <p>Upload an image or take a photo to detect fire or smoke in your data center</p>
487
  </div>
488
  """, unsafe_allow_html=True)
489
 
490
+ # Create tabs for different input methods
491
+ tab1, tab2 = st.tabs(["📁 Upload File", "📱 Take Photo"])
492
+
493
+ image = None
494
+ image_source = None
495
+
496
+ with tab1:
497
+ uploaded_file = st.file_uploader(
498
+ "Choose an image...",
499
+ type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
500
+ help="Upload an image from your data center for fire detection"
501
+ )
502
+
503
+ if uploaded_file is not None:
504
+ image = Image.open(uploaded_file)
505
+ image_source = "uploaded"
506
+
507
+ with tab2:
508
+ # Camera input for mobile devices
509
+ camera_photo = st.camera_input(
510
+ "Take a picture",
511
+ help="Use your device's camera to take a photo for fire detection"
512
+ )
513
+
514
+ if camera_photo is not None:
515
+ image = Image.open(camera_photo)
516
+ image_source = "camera"
517
 
518
+ # Process the image (whether uploaded or from camera)
519
+ if image is not None:
520
+ # Display the image with appropriate caption
521
+ caption = "Uploaded Image" if image_source == "uploaded" else "Camera Photo"
522
+ st.image(image, caption=caption, use_column_width=True)
523
 
524
  # Get prediction
525
  transform = get_inference_transform()
 
535
  with st.expander("🔬 Technical Details"):
536
  st.markdown(f"""
537
  **Prediction Details:**
538
+ - Input Source: {image_source.title()}
539
  - Predicted Class: {predicted_label}
540
  - Confidence Score: {confidence_score:.4f}
541
  - Fire Probability: {all_probs[0]:.4f}