""" Auto-upload script that automatically proceeds with upload """ import os from huggingface_hub import HfApi def auto_upload(): """Automatically upload to Hugging Face""" print("šŸš€ AUTO-UPLOADING TO HUGGING FACE") print("=" * 50) try: token = os.getenv("HF_TOKEN") if not token: print("āŒ HF_TOKEN not found") print("Please run: hf_upload.py to set up your token first") return False api = HfApi(token=token) # Test token try: user_info = api.whoami() print(f"āœ… Logged in as: {user_info['name']}") except Exception as e: print(f"āŒ Token invalid: {e}") return False print("\nšŸ“ Creating model card...") # Create README.md readme_content = """--- title: Singtel Bill Scanner emoji: šŸ“± colorFrom: red colorTo: orange sdk: streamlit sdk_version: 1.28.0 app_file: app.py pinned: false tags: - computer-vision - ocr - trocr - bill-processing - singtel - document-ai --- # Singtel Bill Scanner šŸ“±šŸ’” An AI-powered optical character recognition (OCR) system specifically designed for processing Singtel telecommunications bills. ## šŸš€ Try the Live Demo Upload your Singtel bill image and get instant results! ## Features - šŸ” **Text Extraction**: Uses Microsoft TrOCR for accurate OCR - šŸ“Š **Bill Parsing**: Extracts amounts, dates, account numbers - ⚔ **Fast Processing**: Real-time results - šŸŽÆ **Singtel Optimized**: Tailored for Singtel bill formats - šŸ”’ **Privacy First**: Images processed locally, not stored ## How to Use 1. šŸ“ø Take a clear photo of your Singtel bill 2. šŸ“¤ Upload the image using the interface above 3. šŸ” Click "Extract Information" 4. šŸ“Š View the extracted data ## Technical Details - **Model**: Microsoft TrOCR (microsoft/trocr-base-handwritten) - **Framework**: Streamlit + Hugging Face Transformers - **Processing**: ~3-5 seconds per image - **Accuracy**: High for clear, well-lit images ## Local Installation ```bash git clone https://huggingface.co/spaces/Cosmo125/Singtel_Bill_Scanner cd Singtel_Bill_Scanner pip install -r requirements.txt streamlit run app.py ``` ## API Usage ```python from transformers import pipeline from PIL import Image # Load model pipe = pipeline("image-to-text", model="microsoft/trocr-base-handwritten") # Process image image = Image.open("bill.jpg") result = pipe(image) text = result[0]['generated_text'] ``` --- *Created for the Singtel community with ā¤ļø* """ with open("README.md", "w", encoding="utf-8") as f: f.write(readme_content) print("āœ… README.md created") print("\nšŸ“¤ Starting upload to Hugging Face Spaces...") print("ā³ This may take a few minutes...") api.upload_folder( folder_path=".", repo_id="Cosmo125/Singtel_Bill_Scanner", repo_type="space", ignore_patterns=[ "*.pyc", "__pycache__/", ".venv/", "test_*.png", "test_*.jpg", "sample_*.jpg", ".git/", "*.log" ], commit_message="šŸš€ Deploy Singtel Bill Scanner - AI OCR Web App" ) print("\nšŸŽ‰ SUCCESS! Upload completed!") print("=" * 60) print("šŸ”— Your Singtel Bill Scanner is now live at:") print(" https://huggingface.co/spaces/Cosmo125/Singtel_Bill_Scanner") print() print("šŸ“± Features available:") print(" - Live web interface for bill scanning") print(" - AI-powered text extraction") print(" - Real-time bill parsing") print(" - JSON export functionality") print() print("ā° Note: It may take 2-3 minutes for the app to build and become available") print("šŸ”„ If you see 'Building...', just wait and refresh the page") print("=" * 60) return True except Exception as e: print(f"āŒ Upload failed: {e}") print("\nšŸ”§ Common solutions:") print("1. Check your internet connection") print("2. Verify HF token has write permissions") print("3. Try again in a few minutes") return False if __name__ == "__main__": auto_upload()