Neylton commited on
Commit
fc12075
Β·
verified Β·
1 Parent(s): 6b56229

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -96
app.py CHANGED
@@ -522,108 +522,58 @@ def main():
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
 
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