File size: 4,598 Bytes
795183d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""

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