|
"""
|
|
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)
|
|
|
|
|
|
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...")
|
|
|
|
|
|
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()
|
|
|