Upload app.py
Browse files
app.py
CHANGED
|
@@ -193,37 +193,22 @@ st.markdown("""
|
|
| 193 |
object-fit: contain;
|
| 194 |
}
|
| 195 |
|
| 196 |
-
/*
|
| 197 |
.stTabs {
|
| 198 |
margin-top: 10px;
|
| 199 |
}
|
| 200 |
|
| 201 |
.stTabs > div > div > div > div {
|
| 202 |
-
padding:
|
| 203 |
font-weight: bold;
|
| 204 |
-
border: none;
|
| 205 |
-
background: transparent;
|
| 206 |
-
color: #333;
|
| 207 |
border-radius: 8px;
|
| 208 |
margin-right: 5px;
|
| 209 |
-
transition: all 0.3s ease;
|
| 210 |
}
|
| 211 |
|
| 212 |
.stTabs > div > div > div > div[aria-selected="true"] {
|
| 213 |
background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
|
| 214 |
color: white !important;
|
| 215 |
border-radius: 8px;
|
| 216 |
-
box-shadow: 0 2px 8px rgba(116, 185, 255, 0.3);
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
.stTabs > div > div > div > div:hover {
|
| 220 |
-
background: rgba(116, 185, 255, 0.1);
|
| 221 |
-
color: #0984e3;
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
/* Fix tab underline */
|
| 225 |
-
.stTabs > div > div > div {
|
| 226 |
-
border-bottom: none;
|
| 227 |
}
|
| 228 |
|
| 229 |
/* Camera input styling */
|
|
@@ -263,20 +248,6 @@ st.markdown("""
|
|
| 263 |
max-height: 300px;
|
| 264 |
}
|
| 265 |
|
| 266 |
-
/* Mobile-specific file uploader improvements */
|
| 267 |
-
.stFileUploader > div > div > div > div {
|
| 268 |
-
padding: 15px;
|
| 269 |
-
border-radius: 10px;
|
| 270 |
-
border: 2px dashed #74b9ff;
|
| 271 |
-
background: rgba(116, 185, 255, 0.05);
|
| 272 |
-
text-align: center;
|
| 273 |
-
}
|
| 274 |
-
|
| 275 |
-
.stFileUploader > div > div > div > div:hover {
|
| 276 |
-
border-color: #0984e3;
|
| 277 |
-
background: rgba(116, 185, 255, 0.1);
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
/* Make tabs more touch-friendly on mobile */
|
| 281 |
.stTabs > div > div > div > div {
|
| 282 |
padding: 12px 16px;
|
|
@@ -530,68 +501,46 @@ def main():
|
|
| 530 |
""", unsafe_allow_html=True)
|
| 531 |
|
| 532 |
# Create tabs for different input methods
|
| 533 |
-
tab1, tab2 = st.tabs(["
|
| 534 |
|
| 535 |
image = None
|
| 536 |
image_source = None
|
| 537 |
|
| 538 |
with tab1:
|
| 539 |
-
st.markdown(""
|
| 540 |
-
<div style="background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
|
| 541 |
-
padding: 15px; border-radius: 10px; margin: 10px 0;
|
| 542 |
-
border: 2px solid #81c784; text-align: center;">
|
| 543 |
-
<h4 style="color: #2e7d32; margin: 0;">π± Best for Mobile Users</h4>
|
| 544 |
-
<p style="color: #388e3c; margin: 5px 0; font-size: 14px;">
|
| 545 |
-
Click "Browse files" β "Camera" to open your phone's camera app
|
| 546 |
-
</p>
|
| 547 |
-
</div>
|
| 548 |
-
""", unsafe_allow_html=True)
|
| 549 |
|
| 550 |
-
#
|
| 551 |
-
|
| 552 |
-
"
|
| 553 |
-
|
| 554 |
-
help="On mobile: Tap 'Browse files' then select 'Camera' to take a photo, or 'Photo Library' to upload existing images",
|
| 555 |
-
key="mobile_uploader"
|
| 556 |
)
|
| 557 |
|
| 558 |
-
if
|
| 559 |
-
image = Image.open(
|
| 560 |
-
image_source = "
|
| 561 |
|
| 562 |
with tab2:
|
| 563 |
-
st.markdown(""
|
| 564 |
-
<div style="background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
|
| 565 |
-
padding: 15px; border-radius: 10px; margin: 10px 0;
|
| 566 |
-
border: 2px solid #64b5f6; text-align: center;">
|
| 567 |
-
<h4 style="color: #1976d2; margin: 0;">π» Desktop Upload</h4>
|
| 568 |
-
<p style="color: #1976d2; margin: 5px 0; font-size: 14px;">
|
| 569 |
-
Select an image file from your computer
|
| 570 |
-
</p>
|
| 571 |
-
</div>
|
| 572 |
-
""", unsafe_allow_html=True)
|
| 573 |
|
| 574 |
-
#
|
| 575 |
-
|
| 576 |
-
"Choose an image
|
| 577 |
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 578 |
-
help="Upload an image from your
|
| 579 |
-
key="desktop_uploader"
|
| 580 |
)
|
| 581 |
|
| 582 |
-
if
|
| 583 |
-
image = Image.open(
|
| 584 |
-
image_source = "
|
| 585 |
|
| 586 |
# Process the image (whether uploaded or from camera)
|
| 587 |
if image is not None:
|
| 588 |
# Display the image with appropriate caption
|
| 589 |
caption_map = {
|
| 590 |
-
"
|
| 591 |
-
"
|
| 592 |
-
"camera": "π· Camera Photo"
|
| 593 |
}
|
| 594 |
-
caption = caption_map.get(image_source, "
|
| 595 |
st.image(image, caption=caption, use_column_width=True)
|
| 596 |
|
| 597 |
# Get prediction
|
|
|
|
| 193 |
object-fit: contain;
|
| 194 |
}
|
| 195 |
|
| 196 |
+
/* Simplified tab styling */
|
| 197 |
.stTabs {
|
| 198 |
margin-top: 10px;
|
| 199 |
}
|
| 200 |
|
| 201 |
.stTabs > div > div > div > div {
|
| 202 |
+
padding: 10px 15px;
|
| 203 |
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
| 204 |
border-radius: 8px;
|
| 205 |
margin-right: 5px;
|
|
|
|
| 206 |
}
|
| 207 |
|
| 208 |
.stTabs > div > div > div > div[aria-selected="true"] {
|
| 209 |
background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
|
| 210 |
color: white !important;
|
| 211 |
border-radius: 8px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
}
|
| 213 |
|
| 214 |
/* Camera input styling */
|
|
|
|
| 248 |
max-height: 300px;
|
| 249 |
}
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
/* Make tabs more touch-friendly on mobile */
|
| 252 |
.stTabs > div > div > div > div {
|
| 253 |
padding: 12px 16px;
|
|
|
|
| 501 |
""", unsafe_allow_html=True)
|
| 502 |
|
| 503 |
# Create tabs for different input methods
|
| 504 |
+
tab1, tab2 = st.tabs(["π· Camera", "π Upload"])
|
| 505 |
|
| 506 |
image = None
|
| 507 |
image_source = None
|
| 508 |
|
| 509 |
with tab1:
|
| 510 |
+
st.markdown("**π± Take a Live Photo**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
|
| 512 |
+
# Direct camera input - this opens native mobile camera
|
| 513 |
+
camera_photo = st.camera_input(
|
| 514 |
+
"πΈ Take a picture",
|
| 515 |
+
help="Click to access your device camera and take a photo for fire detection"
|
|
|
|
|
|
|
| 516 |
)
|
| 517 |
|
| 518 |
+
if camera_photo is not None:
|
| 519 |
+
image = Image.open(camera_photo)
|
| 520 |
+
image_source = "camera"
|
| 521 |
|
| 522 |
with tab2:
|
| 523 |
+
st.markdown("**π Upload from Device**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
|
| 525 |
+
# File uploader for existing images
|
| 526 |
+
uploaded_file = st.file_uploader(
|
| 527 |
+
"Choose an image...",
|
| 528 |
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 529 |
+
help="Upload an existing image from your device for fire detection"
|
|
|
|
| 530 |
)
|
| 531 |
|
| 532 |
+
if uploaded_file is not None:
|
| 533 |
+
image = Image.open(uploaded_file)
|
| 534 |
+
image_source = "uploaded"
|
| 535 |
|
| 536 |
# Process the image (whether uploaded or from camera)
|
| 537 |
if image is not None:
|
| 538 |
# Display the image with appropriate caption
|
| 539 |
caption_map = {
|
| 540 |
+
"camera": "π· Camera Photo",
|
| 541 |
+
"uploaded": "π Uploaded Image"
|
|
|
|
| 542 |
}
|
| 543 |
+
caption = caption_map.get(image_source, "Image")
|
| 544 |
st.image(image, caption=caption, use_column_width=True)
|
| 545 |
|
| 546 |
# Get prediction
|