Upload app.py
Browse files
app.py
CHANGED
|
@@ -522,17 +522,109 @@ def main():
|
|
| 522 |
</div>
|
| 523 |
""", unsafe_allow_html=True)
|
| 524 |
|
| 525 |
-
# Mobile
|
| 526 |
st.markdown("**π± Take Photo or Upload Image**")
|
| 527 |
-
st.markdown("πΈ **On Mobile**: Tap 'Browse files' below β Choose 'Camera' to take photo")
|
| 528 |
-
st.markdown("π» **On Desktop**: Click 'Browse files' below to select image files")
|
| 529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
uploaded_file = st.file_uploader(
|
| 531 |
-
"πΈ Tap
|
| 532 |
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 533 |
-
help="π± Mobile: Tap
|
| 534 |
)
|
| 535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
# Process the uploaded image
|
| 537 |
image = None
|
| 538 |
image_source = "uploaded"
|
|
|
|
| 522 |
</div>
|
| 523 |
""", unsafe_allow_html=True)
|
| 524 |
|
| 525 |
+
# Mobile Camera Instructions
|
| 526 |
st.markdown("**π± Take Photo or Upload Image**")
|
|
|
|
|
|
|
| 527 |
|
| 528 |
+
# Add helpful mobile instructions
|
| 529 |
+
st.info("πΈ **Mobile Users**: The file uploader below will automatically show 'Camera' option when you tap it on mobile devices!")
|
| 530 |
+
|
| 531 |
+
# Enhanced file uploader with mobile camera support
|
| 532 |
uploaded_file = st.file_uploader(
|
| 533 |
+
"πΈ Tap here β Camera (Mobile) | π Browse files (Desktop)",
|
| 534 |
type=['jpg', 'jpeg', 'png', 'bmp', 'tiff'],
|
| 535 |
+
help="π± Mobile: Tap this button and select 'Camera' option | π» Desktop: Click to browse files"
|
| 536 |
)
|
| 537 |
|
| 538 |
+
# Enhanced mobile camera support with continuous monitoring
|
| 539 |
+
st.markdown("""
|
| 540 |
+
<style>
|
| 541 |
+
/* Enhanced file uploader styling for mobile */
|
| 542 |
+
.stFileUploader label {
|
| 543 |
+
font-size: 1.1rem !important;
|
| 544 |
+
font-weight: bold !important;
|
| 545 |
+
color: #0984e3 !important;
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
.stFileUploader button {
|
| 549 |
+
background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
|
| 550 |
+
color: white !important;
|
| 551 |
+
border: none !important;
|
| 552 |
+
border-radius: 10px !important;
|
| 553 |
+
padding: 12px 20px !important;
|
| 554 |
+
font-size: 1.1rem !important;
|
| 555 |
+
font-weight: bold !important;
|
| 556 |
+
box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3) !important;
|
| 557 |
+
transition: all 0.3s ease !important;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
.stFileUploader button:hover {
|
| 561 |
+
transform: translateY(-2px) !important;
|
| 562 |
+
box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4) !important;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
/* Mobile specific enhancements */
|
| 566 |
+
@media (max-width: 768px) {
|
| 567 |
+
.stFileUploader button {
|
| 568 |
+
padding: 15px 25px !important;
|
| 569 |
+
font-size: 1.2rem !important;
|
| 570 |
+
width: 100% !important;
|
| 571 |
+
margin: 10px 0 !important;
|
| 572 |
+
}
|
| 573 |
+
}
|
| 574 |
+
</style>
|
| 575 |
+
|
| 576 |
+
<script>
|
| 577 |
+
// Aggressive mobile camera support - continuously monitor and fix file inputs
|
| 578 |
+
function enableMobileCamera() {
|
| 579 |
+
const fileInputs = document.querySelectorAll('input[type="file"]');
|
| 580 |
+
fileInputs.forEach(input => {
|
| 581 |
+
// Set multiple attributes to ensure camera appears
|
| 582 |
+
input.setAttribute('accept', 'image/*');
|
| 583 |
+
input.setAttribute('capture', 'environment');
|
| 584 |
+
input.setAttribute('multiple', 'false');
|
| 585 |
+
|
| 586 |
+
// Remove any existing event listeners to avoid duplicates
|
| 587 |
+
input.removeEventListener('click', handleFileClick);
|
| 588 |
+
input.addEventListener('click', handleFileClick);
|
| 589 |
+
});
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
function handleFileClick(e) {
|
| 593 |
+
const input = e.target;
|
| 594 |
+
// Force camera attributes right before opening
|
| 595 |
+
input.setAttribute('accept', 'image/*');
|
| 596 |
+
input.setAttribute('capture', 'environment');
|
| 597 |
+
|
| 598 |
+
// Small delay to ensure attributes are set
|
| 599 |
+
setTimeout(() => {
|
| 600 |
+
input.setAttribute('accept', 'image/*');
|
| 601 |
+
input.setAttribute('capture', 'environment');
|
| 602 |
+
}, 10);
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
// Run immediately and continuously
|
| 606 |
+
enableMobileCamera();
|
| 607 |
+
|
| 608 |
+
// Monitor for new file inputs (Streamlit creates them dynamically)
|
| 609 |
+
const observer = new MutationObserver(function(mutations) {
|
| 610 |
+
mutations.forEach(function(mutation) {
|
| 611 |
+
if (mutation.type === 'childList') {
|
| 612 |
+
enableMobileCamera();
|
| 613 |
+
}
|
| 614 |
+
});
|
| 615 |
+
});
|
| 616 |
+
|
| 617 |
+
// Start observing the entire document for changes
|
| 618 |
+
observer.observe(document.body, {
|
| 619 |
+
childList: true,
|
| 620 |
+
subtree: true
|
| 621 |
+
});
|
| 622 |
+
|
| 623 |
+
// Also run periodically as backup
|
| 624 |
+
setInterval(enableMobileCamera, 1000);
|
| 625 |
+
</script>
|
| 626 |
+
""", unsafe_allow_html=True)
|
| 627 |
+
|
| 628 |
# Process the uploaded image
|
| 629 |
image = None
|
| 630 |
image_source = "uploaded"
|