Upload app.py
Browse files
app.py
CHANGED
|
@@ -522,108 +522,58 @@ def main():
|
|
| 522 |
</div>
|
| 523 |
""", unsafe_allow_html=True)
|
| 524 |
|
| 525 |
-
# Mobile
|
| 526 |
st.markdown("**π± Take Photo or Upload Image**")
|
| 527 |
|
| 528 |
-
#
|
| 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 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 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 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
input.setAttribute('capture', 'environment');
|
| 597 |
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
|
|
|
|
|
|
| 622 |
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
|
|
|
|
|
|
| 627 |
|
| 628 |
# Process the uploaded image
|
| 629 |
image = None
|
|
|
|
| 522 |
</div>
|
| 523 |
""", unsafe_allow_html=True)
|
| 524 |
|
| 525 |
+
# Mobile-friendly file uploader
|
| 526 |
st.markdown("**π± Take Photo or Upload Image**")
|
| 527 |
|
| 528 |
+
# Clear mobile instructions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
st.markdown("""
|
| 530 |
+
<div style="background: #e3f2fd; padding: 15px; border-radius: 10px; margin: 15px 0; border-left: 4px solid #2196f3;">
|
| 531 |
+
<p style="margin: 0; color: #1976d2; font-weight: bold;">π± Mobile Users:</p>
|
| 532 |
+
<p style="margin: 5px 0 0 0; color: #1976d2;">
|
| 533 |
+
Tap "Browse files" below β Select <strong>"Camera"</strong> to take a photo<br>
|
| 534 |
+
Or select <strong>"Photos"</strong> to choose from gallery
|
| 535 |
+
</p>
|
| 536 |
+
</div>
|
| 537 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
|
| 539 |
+
# Troubleshooting info
|
| 540 |
+
with st.expander("π§ Camera not working? Click here for help"):
|
| 541 |
+
st.markdown("""
|
| 542 |
+
**If you don't see the Camera option:**
|
|
|
|
| 543 |
|
| 544 |
+
1. **β
Check your browser:**
|
| 545 |
+
- Use Chrome, Safari, or Firefox (latest versions)
|
| 546 |
+
- Edge or other browsers may not support camera
|
| 547 |
+
|
| 548 |
+
2. **π Ensure secure connection:**
|
| 549 |
+
- Camera requires HTTPS (β
Hugging Face uses HTTPS)
|
| 550 |
+
- Local development requires HTTPS for camera access
|
| 551 |
+
|
| 552 |
+
3. **π± Mobile device requirements:**
|
| 553 |
+
- iOS: Safari 11+ or Chrome 64+
|
| 554 |
+
- Android: Chrome 53+ or Firefox 68+
|
| 555 |
+
- Some older devices may not support camera
|
| 556 |
+
|
| 557 |
+
4. **π οΈ Try these steps:**
|
| 558 |
+
- Refresh the page and try again
|
| 559 |
+
- Clear browser cache and cookies
|
| 560 |
+
- Try a different browser
|
| 561 |
+
- Check if camera works on other websites
|
| 562 |
+
|
| 563 |
+
5. **π Alternative options:**
|
| 564 |
+
- Take photo with your camera app first
|
| 565 |
+
- Then select "Photos" to upload the saved image
|
| 566 |
+
- Or use the desktop version for file upload
|
| 567 |
+
""")
|
| 568 |
+
|
| 569 |
+
st.info("π‘ **Note**: Camera access depends on your browser and device. If it doesn't work, you can still upload photos from your gallery!")
|
| 570 |
|
| 571 |
+
# Standard Streamlit file uploader
|
| 572 |
+
uploaded_file = st.file_uploader(
|
| 573 |
+
"Browse files",
|
| 574 |
+
type=['jpg', 'jpeg', 'png'],
|
| 575 |
+
help="π± Mobile: Tap to see Camera and Photos options | π» Desktop: Click to browse files"
|
| 576 |
+
)
|
| 577 |
|
| 578 |
# Process the uploaded image
|
| 579 |
image = None
|