Upload app.py
Browse files
app.py
CHANGED
|
@@ -193,16 +193,37 @@ st.markdown("""
|
|
| 193 |
object-fit: contain;
|
| 194 |
}
|
| 195 |
|
| 196 |
-
/* Mobile-friendly camera and tabs */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
.stTabs > div > div > div > div {
|
| 198 |
-
padding:
|
| 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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
}
|
| 207 |
|
| 208 |
/* Camera input styling */
|
|
@@ -241,6 +262,27 @@ st.markdown("""
|
|
| 241 |
.stImage > img {
|
| 242 |
max-height: 300px;
|
| 243 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
}
|
| 245 |
</style>
|
| 246 |
""", unsafe_allow_html=True)
|
|
@@ -488,37 +530,68 @@ def main():
|
|
| 488 |
""", unsafe_allow_html=True)
|
| 489 |
|
| 490 |
# Create tabs for different input methods
|
| 491 |
-
tab1, tab2 = st.tabs(["
|
| 492 |
|
| 493 |
image = None
|
| 494 |
image_source = None
|
| 495 |
|
| 496 |
with tab1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
uploaded_file = st.file_uploader(
|
| 498 |
-
"
|
| 499 |
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 500 |
-
help="
|
|
|
|
| 501 |
)
|
| 502 |
|
| 503 |
if uploaded_file is not None:
|
| 504 |
image = Image.open(uploaded_file)
|
| 505 |
-
image_source = "
|
| 506 |
|
| 507 |
with tab2:
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
)
|
| 513 |
|
| 514 |
-
if
|
| 515 |
-
image = Image.open(
|
| 516 |
-
image_source = "
|
| 517 |
|
| 518 |
# Process the image (whether uploaded or from camera)
|
| 519 |
if image is not None:
|
| 520 |
# Display the image with appropriate caption
|
| 521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
st.image(image, caption=caption, use_column_width=True)
|
| 523 |
|
| 524 |
# Get prediction
|
|
|
|
| 193 |
object-fit: contain;
|
| 194 |
}
|
| 195 |
|
| 196 |
+
/* Mobile-friendly camera and tabs - Fixed styling */
|
| 197 |
+
.stTabs {
|
| 198 |
+
margin-top: 10px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
.stTabs > div > div > div > div {
|
| 202 |
+
padding: 8px 12px;
|
| 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 */
|
|
|
|
| 262 |
.stImage > img {
|
| 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;
|
| 283 |
+
font-size: 1rem;
|
| 284 |
+
min-height: 44px;
|
| 285 |
+
}
|
| 286 |
}
|
| 287 |
</style>
|
| 288 |
""", unsafe_allow_html=True)
|
|
|
|
| 530 |
""", unsafe_allow_html=True)
|
| 531 |
|
| 532 |
# Create tabs for different input methods
|
| 533 |
+
tab1, tab2 = st.tabs(["π± Mobile Camera", "π Upload File"])
|
| 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 |
+
# Mobile-optimized file uploader
|
| 551 |
uploaded_file = st.file_uploader(
|
| 552 |
+
"π± Tap to Take Photo or Upload Image",
|
| 553 |
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 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 uploaded_file is not None:
|
| 559 |
image = Image.open(uploaded_file)
|
| 560 |
+
image_source = "mobile"
|
| 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 |
+
# Desktop file uploader
|
| 575 |
+
desktop_file = st.file_uploader(
|
| 576 |
+
"Choose an image file...",
|
| 577 |
+
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 578 |
+
help="Upload an image from your computer for fire detection",
|
| 579 |
+
key="desktop_uploader"
|
| 580 |
)
|
| 581 |
|
| 582 |
+
if desktop_file is not None:
|
| 583 |
+
image = Image.open(desktop_file)
|
| 584 |
+
image_source = "desktop"
|
| 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 |
+
"mobile": "π± Mobile Photo",
|
| 591 |
+
"desktop": "π» Desktop Image",
|
| 592 |
+
"camera": "π· Camera Photo"
|
| 593 |
+
}
|
| 594 |
+
caption = caption_map.get(image_source, "Uploaded Image")
|
| 595 |
st.image(image, caption=caption, use_column_width=True)
|
| 596 |
|
| 597 |
# Get prediction
|